我试图从数据填充两个组合框,但不知道如何将两个组合框之间划分这个数据。数据现在填充在两个组合框中。如何从文本文件填充在Java中两个组合框?
这里是我的数据文本文件:
[Gates]
value1
value2
value3
[Mids]
customer1
customer2
,这里是我的Java内部代码Swing GUI应用程序:
private void populateCombos() throws FileNotFoundException {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(frmGottApplication);
BufferedReader input=new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = fileChooser.getSelectedFile();
textFieldLoadConfig.setText(selectedFile.getAbsolutePath());
lblConfRes.setText("Loaded " + selectedFile.getAbsolutePath().toString());
} else {
lblConfRes.setText("You didn't load...");
}
List<String> strings = new ArrayList<String>();
try {
String line = null;
try {
while ((line = input.readLine()) != null) {
strings.add(line);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} finally {
try {
input.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
String[] lineArrayGates = strings.toArray(new String[] {});
comboBoxGate.removeAllItems();
comboBoxMid.removeAllItems();
for (String str : lineArrayGates) {
comboBoxGate.addItem(str);
comboBoxMid.addItem(str);
}
}
当它从代码看到我在读从外部文本数据文件,然后尝试在两个不同的组合框中加载它。但是如何编写将门的值分为第一个组合和中间值分配到第二个组合的代码。 任何想法建议? 感谢