I want to perform some action when a mouse is over JMenuItem. What listener should I use?
Use MouseListener. Its method mouseEntered() and mouseExited() will be helpful to you.
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).
精彩评论