Populating JTable with 2 arrays (Netbeans)
Hi,
I have the following issue:
In Netbeans IDE (6.8) I created JTable - name: tblInput; 2 columns, 0 rows, not resizable, not editable, data type - Float.
In Inspector panel I see that JTable is included in JScrollPane.
I also created 2 ArrayLists and converted to arrays:
Code:
ArrayList<Float> data1 = new ArrayList<Float>();
ArrayList<Float> data2 = new ArrayList<Float>();
{here code for populating ArratLists}
Object d1[]=data1.toArray();
Object d2[]=data2.toArray();
Now I try to populate (and display) jTable where col1->d1[], col2->d2
My code for this part is:
Code:
DefaultTableModel model = new DefaultTableModel();
tblInput=new JTable(model);
for (int d=0;d<d1.length;d++){
model.setRowCount(model.getRowCount()+1);
model.addRow(new Object[]{d1[d],d2[d]});
}
When I run the application I do not obtain any errors or Exceptions, but the JTable is still empty. Should I somehow "repaint" JTable component? I am quite new to Java so that I assume it can be the issue of the code above. Or maybe I should do sth with JScrollPane as well?