开发者

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

开发者 https://www.devze.com 2023-03-01 12:44 出处:网络
开发者_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 altern
开发者_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

精彩评论

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