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

后端 未结 3 748
无人及你
无人及你 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:34

    You can't. Nobody has a reference to those objects. In order to be able to remove them you'll need to store it as a data member/variable in your code and then pass that variable to the removeActionListener() method. However, what you could do is use the getActionListeners() method to get an array of all of the ActionListener objects associated with the Button. You'll then need to figure out which one to remove, but if there's only one, that should be easy ;-)

提交回复
热议问题