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().
Related
After a switch of JRE from J8 to J11 JComboBox instances in two different JPanels respectively (both in a JDesktopPane) don't display the popup menu when a respective containing JPanel is not in the focus when a click is happening.
The first click brings focus into the respective JPanel. After that a single click on JComboBox causes the menu to pop up.
This changed when I switched the JRE from 8 to 11.
From the end user perspective it looks like a mess, because most components on the panel don't act like this and correctly do mouse click stuff regardless of the parent panel focus status.
It was this commit for this ticket: JInternalFrame generates UngrabEvent when unselected, which causes JComboBox popup to hide.
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.
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
I am developing a Java application using Swing. I am using menu bar in my application. Whenever I click a menu item I need to open a new panel/frame within the window containing menu options.
To be precise I don't want to open a new window on clicking a menu item. What is the possible solution to this problem?
Thanks in advance.
If you want to put windows inside of other windows, you should look at JInternalFrame:
http://download.oracle.com/javase/tutorial/uiswing/components/internalframe.html
If you don't want to open a new window when clicking a menu item, CardLayout is a good choice. Also, don't overlook the convenience of using actions in your menus.
My problem is this
I want to show a popup menu to a menu item in java, this i can easily achieve,
but when i am showing the popup menu the parent menu clears,
behaviour i want is parent menu also should be visible while showing popup menu
May I first ask "why"? It seems like very uncommon, thus bad usability. There's a good reason why you don't see this in any main stream application. If you want submenu, use submenu like trashgod's sample.
You can add a PopupMenuListener to your parent menu's popup menu, break at popupMenuWillBecomeInvisible and see the call stack. In JDK6, It comes from BasicMenuItemUI#doClick calling MenuSelectionManager#clearSelectedPath.
So if you really have a good reason to surprise user, supply your own menu item UI.
I'm looking at two demos, PopupMenuDemo and GraphPanel, and I don't see any clearing. PopupMenuDemo shows a hierarchical submenu, while GraphPanel shows a hierarchical context menu. Do you have an example in which "the parent menu clears."
Addendum: Here's what I see for PopupMenuDemo. Neither demo appears to invoke setVisible() on the menu.