Friday, April 8, 2011

What event would I need to be able to tell that the mouse was moved over a JMenuItem?

I'd like to handle the case where the mouse goes over any of the JMenuItems. I don't need the user to click one of the JMenuItems; simply to move the mouse over any of them. Basically, he has to click the JMenuBar to show the menus, but he doesn't have to click any menu item.

I wanted to use an actionPerformed listener on the JMenuBar - since the menu items and submenus only appear once the user clicks the JMenuBar - but that doesn't seem to be possible, unless I did something wrong.

From stackoverflow
  • Implement a MouseListener and add it to the JMenuItems. Then you can catch when the mouse enters and leaves each JMenuItem.

    David Zaslavsky : Specifically, mouseEntered and mouseExited are the methods you need to implement.

0 comments:

Post a Comment