When I code a popup menu, I can check the mouse event and then
before calling show() prepare the menu.
Now I want a similar functionality for drop down menus, that
live in the menu bar. For example I have the following menu
bar layout:
Menu 1
MenuItem 1.1
MenuItem 1.1.1
MenuItem 1.1.2
..
MenuItem 1.1.n
Menu 2
Basically I want to generate the list MenuItem 1.1.1, MenuItem 1.1.2,
…, MenuItem 1.1.n dynamically when the drop down menu is invoked and
before it is shown.
How could I do this in Java/Swing? Is there a call back that covers both
L&F specific keyboard/mouse invokations of the menu bar?
Best Regards
You need to use a
javax.swing.JMenuBarinstead of ajava.awt.MenuBar.These MenuBars can add
javax.swing.JMenus which have aaddMenuListener(MenuListener l)method.In this MenuListener you can dynamically add and delete the menus.
To add the JMenuBar to a JFrame use the
setJMenuBar(JMenuBar menubar)method.