nix
nix

Reputation: 2285

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

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

Upvotes: 2

Views: 211

Answers (3)

Andrew Thompson
Andrew Thompson

Reputation: 168845

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

Upvotes: 2

mKorbel
mKorbel

Reputation: 109823

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
        }
    });

Upvotes: 2

Harry Joy
Harry Joy

Reputation: 59694

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

Upvotes: 5

Related Questions