I’m developping a Java/Swing application with a menu using JMenuBar, JMenu and JMenuItem.
System look and fell is applied to the UI.
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
I have several top level elements for my menu :
-
The JMenu “File” works fine and allows the user to select submenus like JMenuItems “New”, “Open”…
-
Then, I wanna add a second top level element “About” (same level as “File”) that displays a popup when clicking on it.
The issue is quite simple: how to make this JMenu “About” element clickable?
I try several ways:
-
Set the “About” element as a JMenuItem. However, this element has not the same UI that the other JMenu items like “File”
-
Set the “About” element as a JMenu and add a MouseListener and a KeyListener on it. This element will have the same UI that others but I have to click twice on the “Ok” button of the “About” popup to catch this event.
Any other solutions ?
My first suggestion would be to just add a single JMenuItem inside the JMenu “About” menu. As this would match how the other menus operate and would look the same. It would also not be surprising when a user clicks on “About” expecting a menu but sees a popup instead. It is fairly common for applications to have a “Help” menu on the end of a menu bar that has a menu item named “About” that shows a popup. It is not common for the menu title to open a popup when clicked on.
If you really have to do what your propose then either:
or