我已经看到了一个较旧的问题,答案是下面的代码,但是如果我使用 netbeans,我已经设计了我的组合框。所以我认为(正如你想象的那样,我在 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);