Lompat ke konten Lompat ke sidebar Lompat ke footer

Java Populate JCombobox From Text File

How To Fill A JComboBox With Items From Txt File Using Java NetBeans

 How To Fill A JComboBox With Items From Txt File Using Java NetBeans Java Populate JCombobox From Text File



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:

 How To Fill A JComboBox With Items From Txt File Using Java NetBeans Java Populate JCombobox From Text File




Posting Komentar untuk "Java Populate JCombobox From Text File"