我有一个组合框,每一个项目被选中的时候,都有一个对应的JList显示了在面板上,并JList中通过一个文本文件填充。如何清除一个JList
我的问题是,当我在组合框中的不同项目之间进行选择时,如果前面的列表中有更多的元素,比如说3,而其他元素只有2,那么第三个项目将保留在列表中,其他列表至少包含相同数量的元素。
以下是我的代码。
JList list = new JList();
Path Aparts = Paths.get(".\src\assets\acurap.txt");
String[] partList = new String[50];
String temp2 = "";
teamComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
if (teamComboBox.getSelectedItem().equals("Acura")) {
imageLabel.setIcon(acura);
populatedAcurap();
}
}
void populatedAcurap() {
InputStream input;
try {
input = new BufferedInputStream(Files.newInputStream(Aparts));
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
int i = 0;
temp2 = reader.readLine();
while(temp2 != null) {
partList[i] = temp2;
list.setListData(partList);
temp2 = reader.readLine();
i++;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
不仅缩进错了,你没有关注Java编码惯例Ë ither。你可以在这里阅读更多http://en.wikipedia.org/wiki/Indent_style#K.26R_style一下吧。 – Emz 2014-12-11 02:32:00
列表模式设置为一个新的空模型... – MadProgrammer 2014-12-11 02:33:48