The JMenuBar does not start showing JMenuItems as selected or displaying the JMenu popups until it is first clicked upon. After you click somewhere in the JMenuBar, all these items respond to mouse hovers.
I would like to bypass the initial click required and have it activated automatically upon a mouse hover. Is there a way to do this?
The way is to add a
MouseListeneron theJMenuand listen on eventsmouseEntered. In the event handlers, you just need to click on it usingdoClick. For example,Once programmatically clicked on the mouse is entered, it opens the popup menu automatically. To activate an entire
JMenuBar, you have to add a listener on eachJMenu. For this purpose, it is better to create a listener object separately.I have two menu items on the bar, so I did:
If you have so many menu items on the bar, you can just iterate it: