我正在尝试创建一个将项添加到jlist的循环但是当我放入actionlistener时它似乎没有这样做...
textFieldSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 10; ++i) {
locations[i] = "blah";
}
}
});
答案 0 :(得分:1)
你应该试试这个:
textFieldSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultListModel model = (DefaultListModel) JLISTNAME.getModel();
for (int i = 0; i < 10; ++i) {
model.add(i, "blah");
}
}
});