planetList = new JList(planets);
planetList.addListSelectionListener(this); ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(this); public void valueChanged(ListSelectionEvent event){
//the question is that the listener do not understand what to do. if(event.getValueIsAdjusting()){
JList source = (JList)event.getSource();
Planet value = (Planet)source.getSelectedValue();
// update image and description
planetImage.setIcon(value.getImage());
description.setText(value.getDescription());
}else{
//process table data
int[] selectRow = table.getSelectedRows();
String selectData = null; for(int i=0;i<selectRow.length;i++){
selectData = String.valueOf(table.getValueAt(selectRow[i],0));
}
displayNum.setText(selectData);
}
}
planetList.addListSelectionListener(this); ListSelectionModel selectionModel = table.getSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(this); public void valueChanged(ListSelectionEvent event){
//the question is that the listener do not understand what to do. if(event.getValueIsAdjusting()){
JList source = (JList)event.getSource();
Planet value = (Planet)source.getSelectedValue();
// update image and description
planetImage.setIcon(value.getImage());
description.setText(value.getDescription());
}else{
//process table data
int[] selectRow = table.getSelectedRows();
String selectData = null; for(int i=0;i<selectRow.length;i++){
selectData = String.valueOf(table.getValueAt(selectRow[i],0));
}
displayNum.setText(selectData);
}
}
addXXXListener()
异常:java.lang.ClassCastException:
javax.Swing.DefaultListSlectionModel