Breaking News: Java doesn't have it all figured out
So, I could live with the frustrating fact that JComboBox and JList don't have consistant interfaces, but then I see that the SelectionChanged event gets fired twice when a user selects a new item in a list view. Why? What's the point? There should be two events, like mouse up and mouse down.
Code to get around this:
Components Examples: "twice"
Code to get around this:
public void valueChanged(ListSelectionEvent e)
{
System.out.print( "list select: index: " + list.getSelectedIndex() );
System.out.print( ", value: " + list.getSelectedValue() );
// below indicates how to differentiate mouse-down from mouse-up
if (list.getSelectedIndex() != selected_index)
{
System.out.println( " -- mouse down" );
selected_index = list.getSelectedIndex(); // reset
}
else {
System.out.println( " -- mouse up" );
System.out.println( "-----------------------------------" );
}
}
Components Examples: "twice"
0 Comments:
Post a Comment
<< Home