Why my ChangeListener reacts only for JMenu, and not for JMenuItem?

前端 未结 2 1540
温柔的废话
温柔的废话 2020-12-18 09:59

Now, I have a JMenu, and some JMenuItems in it. I want my program to perform some action when JMenu\'s and JMenuItem\'s state is changed to \"selected\". I don\'t use MouseL

2条回答
  •  独厮守ぢ
    2020-12-18 10:31

    This is the expected polymorphic behavior. The isSelected() method of JMenuItem is inherited from AbstractButton, while the same method in Jmenu is overridden so that it "Returns true if the menu is currently selected (highlighted)."

提交回复
热议问题