Popular Posts

Java Populate JCombobox From Text File

Share it:

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

Fill JCombobox From Text File Using Java



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:

insert items to jcombobx from txt file using java




Share it:

file

Fill A JComboBox With Items From Txt File Using Java

java

java file

java jcombobox

jcombobox

Populate JCombobox From Text File In Java

Post A Comment:

0 comments: