javaswingjpopupmenujmenuitemjpopup

Handle JPopupMenu closed


I want to highlight some elements on screen, when one JMenuItem in PopupMenu ist selected(mouse over). So i use MouseListener on my JMenuItem with

        @Override
        public void mouseEntered(MouseEvent e) {
            highlightOn();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            highlightOff();
        }

It works fine, but if i press Esc the popup menu will be closed, without clean the highligt. How can i intercept the closing of JPopupMenu to handle this?


Solution

  • you look at

    1. PopupMenuListener

    better could be

    1. JMenuItem(s) can returns ButtonModel,

    2. ButtonModel returns isRollover(), isArmend(), isPressed() e.i.

    3. each of JButtons JComponents (JButton, JCheckBox, JRadioButton and JMenuXxx) implemented diferrent methods from ButtonModel