我试图将文本文件的每一行复制到 jcomboBox 中,但它只显示 jcomboBox 中文本文件的第一行......我不明白为什么。你能解释一下有什么问题吗?
(...)
BufferedReader in;
String read;
try {
in = new BufferedReader(new FileReader("D:/File.txt"));
read = in.readLine();
lines[w]=read;
++w;
in.close();
}catch(IOException e){
System.out.println("There was a problem:" + e);
}
combo1 = new JComboBox(lines);
combo1.setPreferredSize(new Dimension(100,20));
combo1.setForeground(Color.blue);
JPanel top = new JPanel();
top.add(label);
top.add(combo1);
combo1.addActionListener(new ActionFichiers());
container.add(top, BorderLayout.NORTH);
this.setContentPane(container);
this.setVisible(true);
}
(...)