Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Hal Vaughan" Subject: Re: Listeners Still Respo Message-ID: <58mdnRXcPeToDAXbnZ2dnUVZ_t7inZ2d@comcast.com> X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: References: Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 52 Date: Wed, 27 Apr 2011 15:36:54 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918614 96.60.20.240 (Wed, 27 Apr 2011 10:36:54 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:36:54 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:2051 To: comp.lang.java.gui Thomas A. Russ wrote: > Hal Vaughan writes: > >> 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? > > My best guess would be that you are adding "this" as a > ListSelectionListener more than once. The remove will only remove a > single instance of the matching listener, not all instances of the > matching listener. That would explain both why you still get updates > after a single removal, as well as why you end up getting multiple > responses. That's what it turned out to be. The problem was one was added within the class and it was added from the class that created it. Since they were in two different places, I didn't make the connection until I took Roedy's suggestion and had it list the listeners, then realized I had to find where it was added the 2nd time. Thanks! Hal --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24