When making a selection on this simple gui list I am getting valueChanged to execute twice once when mouse down and once when mouse up.
import groovy.swing.SwingBuilder
import java.awt.*
import java.swing.*
import javax.swing.*
def main(){
new SwingBuilder().edt {
frame(title:'Testing', pack:true, show:true) {
vbox {
panel(){
textbox = label(text:'null')
}
panel(){
listing = list(valueChanged:{
mess(listing.selectedValue);// this code runs twice
},
listData: ['test','another','test','and','again'])
}
}
}
}
}
def mess(mytext){
new SwingBuilder().edt {
frame(title:'Message', pack:true, show:true){
vbox {
panel(){
label(text:mytext)
}
}
}
}
}
main();
I have looked for other questions similar to this one on stackoverflow to no avail if it is a duplicate I’m sorry and I will remove it but I don’t believe it is. All I’m trying to do it get this to not execute on mouse up.
Yes, with a Swing JList you get two valueChanged events when the user clicks on a row.
The first click will have
event.valueIsAdjusting == trueto indicate the user is in the process of changing the value, and the second event will haveevent.valueIsAdjusting == falseto show the selection has been made (see the evaluation section of this bug report* here and the event documentation here)Changing:
To:
Should fix this…
(* It should be noted that this is not a bug, as can be seen by it’s closure status) 🙂
edit
To clear the selection, you can change
main()to: