Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto remove Listeners on SWING JComponents

is there an easy way to remove all Listeners from a JComponent?

JComponent widget = getComponentOverScaryMethod();
EventListener[] listners = widget.getListeners(EventListener.class);
for (EventListener l : listners) {
    widget.remove*RandomListener*(l);
}

Background:

I have a JComponent with an unknown amount of Listeners (random types). Since the widget should be removed from the visible part (and won't be needed again) it should be destroyed (and the Listeners should be deleted).

Thanks in advance Joan

like image 502
Joan Wilkinson Avatar asked May 31 '11 16:05

Joan Wilkinson


1 Answers

There's a workaround mentioned here:

  • Bug ID: 4380536, I want a method to remove all listeners from a Component
like image 72
aioobe Avatar answered Oct 17 '22 09:10

aioobe