Handling List Selections
public void valueChanged(ListSelectionEvent evt) {
if(! evt.getValueIsAdjusting()) {
String color = (String) list.getSelectedValue() ;
if(color.equals(“black”))
setBackground(Color.black) ;
else if(color.equals(“blue”))
setBackground(Color.blue) ;
. . .
}
}
Typically valueChanged() is dispatched several times during the selection process (to allow for more sophisticated handling strategies). When the final selection has stabilized, the value returned by getValueIsAdjusting() will be false.