I have a list box which fires the valueChanged event each time the selected line changes. This has the unwanted side-effect of firing an event for every line traversed if you press and hold-down the up or down arrow key. Is there a way of getting this event fired only once when the highlight comes to rest on a line (i.e. when the user releases the arrow key)? Are they different events I could handle to achieve that?
Your application could keep track of the mouse buttons
and only respond to valueChanged() when all are up.
This would be done by adding a mouseListener to the JList.
Override mousePressed to set a flag that a button is down
and mouseReleased to clear the flag when all buttons are up.
When I started thinking about this problem,
I found I had to go further and keep track of which keys were down.
The code I wrote used a BitSet to keep track of which keys were down.
It gets worse. On some platforms when a key is held down repeated up/down events are sent.
The problem is discussed at length on an old post.
What is a "list box"? I'm not aware of that component.