Java ListSelectionListener double change value
I have Java class with JList and ListSelectionListener:
final JList myList = new JList();
// ...
myList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent开发者_Go百科 e) {
System.out.println("selected");
}
});
but output is
selected
selected
How should I change my code, that output should be one selected
?
Try
if(e.getValueIsAdjusting())
{
System.out.println("Selected");
}
Look at getValueIsAdjusting.
Returns whether or not this is one in a series of multiple events, where changes are still being made
Only print "selected" when this method returns false.
You will need to refer to:
getValueIsAdjusting()
on the ListSelectionEvent.
From the API: Returns whether or not this is one in a series of multiple events, where changes are still being made.
精彩评论