This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 155789 - ListSelectionListener valueChanged method executed twice
Summary: ListSelectionListener valueChanged method executed twice
Status: RESOLVED INVALID
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: All Windows XP
: P3 blocker (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-18 18:59 UTC by ecrouse
Modified: 2008-12-22 16:28 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ecrouse 2008-12-18 18:59:20 UTC
When I create a JList component on a JFrame window using the GUIDesigner tool and then add a ListSelectionListener to
the JList component, and then running the application and selecting one of the items in the list the valueChanged method
is executed twice instead of only once.

In order to make sure it wasn't my own code I created a very simple frame with the JList as the only component and the
problem persisted. I added the listener using anonymous class and an inner class and neither worked.

I also imported working code (not generated with the form editor) with a simple JList component and ran it with NetBeans
and the valueChanged executed only once as it was supposed to. The form editor code looks fine so perhaps the
EventDispatcher Thread is dispatching the same event more than once???
Comment 1 Jan Stola 2008-12-22 16:28:22 UTC
This is a misunderstanding. The event is delivered "twice" if you change selection using mouse. The first event is 
delivered on mouse-press event and its valueAdjusting property is set to true. This denotes that the selection may not 
be finished (when you move mouse pointer over another item in the list while holding button pressed then another event 
of this type is delivered). When you release mouse button then a new event is generated (with valueAdjusting property 
set to false) denoting that the selection was finalized.

If you don't want to react on temporary selections then your event handler should check whether the delivered event has 
valueAdjusting property set to true and don't react otherwise.