remove.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
Object obj = list.getSelectedValue();
listModel.removeElement(obj);
// listModel.trimToSize();
list = new JList(listModel);
}
});
remove 是JButton
不知道为什么启动程序后只能删除list的一个元素,然后就删不了第二个了,求解
new ActionListener(){
public void actionPerformed(ActionEvent e){
Object obj = list.getSelectedValue();
listModel.removeElement(obj);
// listModel.trimToSize();
list = new JList(listModel);
}
});
remove 是JButton
不知道为什么启动程序后只能删除list的一个元素,然后就删不了第二个了,求解
去掉这行。
ListModel内容变化后,View层的JList会自动更新。