开发者

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

开发者_JAVA技巧

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜