Yes, with Swing JList you get two ValueChanged events when the user clicks on a row.
The first click will have event.valueIsAdjusting == true to indicate that the user is in the process of changing the value, and the second event will have event.valueIsAdjusting == false to show the selection (see this error report * here and in the documentation here )
Change:
valueChanged:{ mess(listing.selectedValue);// this code runs twice }
To:
valueChanged:{ event -> if( !event.valueIsAdjusting ) mess(listing.selectedValue) }
Gotta fix it ...
(* It should be noted that this is not an error, as can be seen from the closing state) :-)
change
To clear the selection, you can change main() to:
def main() { def data = ['test','another','test','and','again'] def codeFired = false new SwingBuilder().edt { frame(title:'Testing', pack:true, show:true) { vbox { panel(){ textbox = label(text:'null') } panel(){ listing = list listData: data, valueChanged: { event -> if( !event.valueIsAdjusting && !codeFired ) { mess( listing.selectedValue ) codeFired = true listing.clearSelection() codeFired = false } } } } } } }
source share