Keep DROP_DOWN ToolItem highlighted while menu is shown - java

I have a ToolItem as SWT.DROP_DOWN, and a selectionListener to popup a Menu with a few menuItem.
The ToolItem is highlighted when mouseover, and on click the submenu appears. However, the ToolItem is no longer highlighted. Is there any way to keep it highlighted until I select one of the menu items (or click from somewhere else to close)?

SWT uses the native widgets of the platform it runs on. Hence, the highlighting behavior is entirely up to the platforms implementation.
I fear there is no way to highlight the tool button while the drop-down menu is shown.

I use CHECK instead of DROP_DOWN, and add MenuListener to the menu and override menuHidden() to deselect the ToolItem. By doing this, ToolItem is selected until the Menu disappears.
To make the ToolItem looks like a dropdown, I can draw the arrow to the item.

Related

Improving the appearance of java.awt.PopupMenu and java.awt.MenuItem?

I'm trying to add a system tray icon, with a right click menu on the icon, for a javafx program.
The answers I've found indicate that the only way to do this is via java.awt.SystemTray
Which is fine, but the popup menu which shows up when I right click the icon in tray, looks very bland. Also, if I hover the mouse over any of the popup menu options, I expect the background color of that option to change, to indicate that I'm selecting it. But this doesn't happen, the menu stays completely static and unchanging until I click an option.
I'm looking for a way that I can listen to the mouseover event on a MenuItem and change its background + foreground color to indicate that it has the focus. But I can't find any methods in the API that let you do this. Is there any other way? Or is there anything else I can do to make the menu seem a bit more responsive?

How do I fire click() event whenever i click on any item in the popupmenu in java?

I want to add a window on clicking the menu item of a right click popupmenu in Java swing(seems like a simple task...but not getting)
I got it to partly work by
adding a custom menuitem in popupmenu
adding a window on right click
But this only partly works. Now I when I right click anywhere a window pops up, but the selected menu item in the popupmenu does not pop up the window.
How can I get window on clicking my menu item? or is there an easier way to do this in java?
I know there are others ways of doing this (in code), but I would prefer to use Java swing
Has anyone ever done this before?
Thanks for your help
please to read Oracle tutorial about How to Use Menus
How to Use Swing Actions and / or with How to Write an Action Listener
a few examples about JPopup /JPopupMenu

Using visual swing JPopup menu in netbeans

i want to add a popup menu to my app but when i add it to my panel i see its disappear.
how i can edit jpopup menu visualy like other menus?
I think you're talking about using the matisse visual designer in NetBeans.
In which case the process is slightly different from creating menubar menus that you can just drag onto the screen.
The steps to get this to work are as follows
Drag a pop up menu on to the screen
Go to the Inspector Window (Window -> Navigating -> Inspector)
You will see an element there - jPopupMenu1
Right click jPopupMenu1 -> Add from Palette
This submenu will show you all the items that can be added to your pop-up menu
After you have selected the item you will see it listed as a child node of jPopupMenu1.
To change the order of your menu items, select an item, right click and select move up or move down.
Don't forget that although you've added the pop-up menu to the form you still need to register the pop-up menu with the component that you want it to activate for, the easiest way to do so is via SetComponentPopupMenu().

Jtextpane click to create popup menu effect on selection not as intended

I have a JTextPane sitting in a JFrame, with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
I want to give the JTextPane a "Word-like" popup behavior. By that I mean, if you right click outside of your current text selection, the caret will reposition to where you right clicked, with menu options that affect a text selection (such as cut, copy, or bold) disabled. If you right click within your current text selection, the popup will appear with options that effect text selection enabled, the text selection will persist, and the caret will not move.
The problem is I cannot seem to find where I can put the code that handles the selection change. I tried:
Using the "PopupMenuWillBecomeVisible" event which is triggered before a popup becomes visible. The event passed into this method does not contain any mouse event information so there is no way for me to use viewtomodel to find out how to modify the selection. I could use MouseInfo but that seems dubious at best.
Using MousePressed/MouseReleased events in the JTextPane or JFrame. Apparently, neither of these events are invoked when a popup menu is triggered. In fact, I still can't determine what the parent component of my popup menu is. (I did read that in windows "MouseReleased" is the popup trigger, while in other systems "MousePressed" is the trigger. I tried both and neither worked).
So, I guess the problem is that I can't seem to find a place to put code where it would be called before the popup menu becomes visible, but has awareness of the mouseEvent that triggered the popup menu. I must be missing something here.
with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
You can use the older approach of displaying the popup based on your own custom MouseListener.
See the section from the Swing tutorial on Bringing Up a Popup Menu. Now you have access to the MouseEvent so you can convert that point to a point in the Document so you know where the click was made, on selected or unselected text.

How to Display Menu Icons after clicking the More item in Android

if I have an Options menu in Android that has more than 6 items, Android adds a More item that shows the other hidden items, AS text!
But I want the More button to display the extra items both in their text AND icon, how do I do that?
I think this is not possible, unless you code that by your self. And by "code" I mean you create a custom menu.

Categories