I want to perform some action when a mouse is over JMenuItem. What listener should I use?

StackOverflow https://stackoverflow.com/questions/5818689

  •  26-10-2019
  •  | 
  •  

Question

I want to perform some action when a mouse is over JMenuItem. What listener should I use?

Was it helpful?

Solution

Use MouseListener. Its method mouseEntered() and mouseExited() will be helpful to you.

OTHER TIPS

and alternative is

    menuItem1.getModel().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            ButtonModel model = (ButtonModel) e.getSource();
            if (model.isRollover()) {
                // some stuff
            }// may be another states from ButtonModel
        }
    });

If 'some action' happens to be 'show a message', look at JComponent.setToolTipText(String).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top