我怎么去做这个,基于textfield中的输入,你在jlist中得到一些结果,在你选择jlist中的选项然后你得到一个动作,代码示例将被赞赏...这是我到目前为止得到的:
final DefaultListModel<String> locations = new DefaultListModel<String>();
getTextFieldSearch().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(int i=0;i<10;++i) {
locations.add(i, "blah");
}
}
});
JList<String> list_racentRaces = new JList<String>(locations);
答案 0 :(得分:1)
首先来看看How to Use Lists,它有很多很棒的代码示例。
基本想法是......
触发actionPerformed
方法后,创建一个新的DefaultListModel
,假设您没有自己的实现,请填写所需的所有新项目并将其应用于{ {1}}
如果您想维护以前在列表中的内容,您应该考虑从list_racentRaces
开始,只需根据需要添加新项目......
然后,将DefaultListModel
附加到ListSelectionListener
,当触发list_racentRaces
事件时,找到所选项目并根据这些结果执行您需要的操作(s )