How To Fill A JComboBox With Items From Txt File Using Java NetBeans
In this Java Tutorial we will see How To Add Items To JCombobox From Text File Using For Loop + Array + BufferedReader In Java NetBeans .
Project Source Code:
public void fillComboFromTxtFile(){
String filePath = "C:\\Users\\Desktop\\file1.txt";
File file = new File(filePath);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
Object[] lines = br.lines().toArray();
for(int i = 0; i < lines.length; i++){
String line = lines[i].toString();
jComboBox1.addItem(line);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(jcombo_items_from_txt_file.class.getName()).log(Level.SEVERE, null, ex);
}
}
OutPut:
Download Projects Source Code
2 comments
commentsThanks! this really helped me :)
ReplyThank you for being yoou
Reply