Alex Burrows
Alex Burrows

Reputation: 29

populate Jtable with array

I have created an array from my csv file and am stuck in putting it in to rows on the JTable

 try {
        BufferedReader br = new BufferedReader(new FileReader(datafile));
        String columnn = br.readLine();

        String[] columnnames = columnn.split("\t");
        DefaultTableModel tableMod = new DefaultTableModel();
        tableMod.setColumnIdentifiers(columnnames);
        jTable1.setModel(tableMod);
        while ((line = br.readLine()) != null) {

            String[] values = line.split("\t");

        for (int i = 0; i < values.length; i++) { 
            System.out.println(values[i]);
        }

}
br.close();
    }

Upvotes: 0

Views: 278

Answers (1)

camickr
camickr

Reputation: 324078

String[] values = line.split("\t");

That doesn't do anything. You need to actually add the data to the model:

tableModel.addRow( line.split("\t") );

You also need to make sure you have added the table to a JScrollPane and the scrollpane is added to the frame.

Upvotes: 2

Related Questions