텍스트 파일의 각 줄을 jcomboBox에 복사하려하지만 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);
}
(...)
와
대체?! :) – Prine
자바의 루프 while while 시도 – DeyyyFF