Alp*_*n67 0 java file-io swing netbeans jcombobox
我已经看到一个较旧的问题,答案是下面的代码,但如果我使用netbeans,我已经设计了我的comboBox.所以我认为(我想象的是Java和netbeans中的新东西!)代码的最后一行应该改变,我在哪里插入这段代码?
BufferedReader input = new BufferedReader(new FileReader(filePath));
List<String> strings = new ArrayList<String>();
try {
String line = null;
while (( line = input.readLine()) != null){
strings.add(line);
}
}
catch (FileNotFoundException e) {
System.err.println("Error, file " + filePath + " didn't exist.");
}
finally {
input.close();
}
String[] lineArray = strings.toArray(new String[]{});
JComboBox comboBox = new JComboBox(lineArray);
Run Code Online (Sandbox Code Playgroud)
这些代码行没用
List<String> strings = new ArrayList<String>();
String[] lineArray = strings.toArray(new String[]{});
JComboBox comboBox = new JComboBox(lineArray);
Run Code Online (Sandbox Code Playgroud)
2. 直接向DefaultComboBoxModel添加一个New Item ,也可以对Items进行排序
3.可以在Swing中读取EDT问题读取Concurency,使用SwingWorker从File加载Items
| 归档时间: |
|
| 查看次数: |
2079 次 |
| 最近记录: |