MyJList myList = new MyJList();
myList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if(!e.getValueIsAdjusting()){
System.out.println("Selected!");
}
}
});
。 。 。Listen JList setSelectedIndex
class MyList extends JList{
public MyList() {
super();
this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.setSelectedIndex(0);
}
}
當我點擊鼠標列表項,我看到消息«已選擇!»。
程序啓動時,不顯示此消息,但選擇了項目#0。
你說得對。謝謝。 – Alexandr 2011-02-28 06:27:02