Listeners Still Respond After Being Removed
- From: Hal Vaughan <hal@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 13 Jul 2007 13:11:21 -0400
I have the following code (with line numbers for convenience):
//jList is a JList
1 jList.setFocusable(false);
2 jList.removeListSelectionListener(this);
3 jList.setListData(new String[0]); //Clear in case new data is empty
//Other code for setting data
11 jList.setSelectedIndex(refIndex);
12 jList.setFocusable(true);
13 jList.addListSelectionListener(this);
14 componentIndex = jList.getSelectedIndex();
I've removed the class itself as the ListSelectionListener at the start (at
line 2), then add it later (at line 13). While testing, I found my data
was being updated more frequently than appropriate and when it was updated,
it would loop through multiple times. I tracked it back, by throwing an
error and printing a stack trace, to both lines 3 and 11. Both of these
lines, at different times, are triggering the ListSelectionListener.
Both of the offending lines are after I've removed the Listener and before I
reattach it. Why are they triggering the Listener when it's not attached?
Hal
.
- Follow-Ups:
- Re: Listeners Still Respond After Being Removed
- From: Roedy Green
- Re: Listeners Still Respond After Being Removed
- From: Thomas A. Russ
- Re: Listeners Still Respond After Being Removed
- Prev by Date: Re: Problem with loaded images after pack()
- Next by Date: Re: Creating a form in SWT
- Previous by thread: Re: Java
- Next by thread: Re: Listeners Still Respond After Being Removed
- Index(es):
Relevant Pages
|
|