JList click event

Hi all,

I have a JList and I would like to go somthing when an item is selected.

So I implemented a ListSelectionEvent and done the following code:

publicvoid valueChanged(ListSelectionEvent e){

if (e.getSource().equals(itemList)){

//do somthing

}

THIS IS WORKING... however not with a whole click of the mouse. It is executed when I click the mouse and executed again when I release the mouse. I would like this to work with a whole click (down and up)

Thanks for the help :)

[742 byte] By [Xenobiusa] at [2007-11-26 23:59:51]
# 1

it shouldn't, are you changing the list selection in the method? Try looking through the API for the differant listeners for JList, ActionListener should be what you want if you only want mouse clicks. ActionListener activates no matter where you click on the JList though, so even if they don't change anything it would execute.

Vagabona at 2007-7-11 15:49:14 > top of Java-index,Java Essentials,New To Java...
# 2
Well if it executes even if the user clicks blank space in the JList then unfortunatelly its not good ! :( I want it to execute when an item from the list is clicked!Thanks thou..any one else have any ideas?thanks
Xenobiusa at 2007-7-11 15:49:14 > top of Java-index,Java Essentials,New To Java...
# 3
Post the whole code and let us look at it.
Vagabona at 2007-7-11 15:49:14 > top of Java-index,Java Essentials,New To Java...
# 4
Well guys,I still have such a problem that when I click on an item, the event is executed both when the mouse is pressed and again when the mouse is released, HOWEVER my code is working fine and am not gonna bother it hehe But thanks a lot! :)
Xenobiusa at 2007-7-11 15:49:14 > top of Java-index,Java Essentials,New To Java...
# 5
ListSelectionEvent has a getValueIsAdjusting() method that might be helpful.
pbrockway2a at 2007-7-11 15:49:14 > top of Java-index,Java Essentials,New To Java...