Java Swing: How to remove an anonymous ActionListener from a component

后端 未结 3 750
无人及你
无人及你 2020-12-06 17:08

I created an array of JButtons with anonymous ActionListeners and under certain conditions I want to remove all the ActionListeners, b

3条回答
  •  一向
    一向 (楼主)
    2020-12-06 17:31

    You can get them with: getActionListeners method:

    for( JButton currentButton: button ) {
        for( ActionListener al : currentButton.getActionListeners() ) {
            currentButton.removeActionListener( al );
        }
    }
    

    I'm not sure if it will thrown a ConcurrentModificationException though.

提交回复
热议问题