Reputation: 187
how to add header and data on DefaultTableModel dtm = new DefaultTableModel();
without putting new DefaultTableModel(inside of this)
?i tried using dtm.add(data,header);
still isn't working..am i going to use a method?what method it is?
For example:
class Table extends JFrame{
DefaultTableModel dtm = new DefaultTableModel();
JTable table = new JTable();
Table(){
table.setModel(dtm);
(.....)
}
public void thisIsAMethod(){
Vector<String> header = new Vector<String>();
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
(.....)
dtm.add(header,data);
}
}
Upvotes: 0
Views: 373
Reputation: 5207
For the whole table:
setDataVector(data , header);
For a single column:
addColumn(columnName, columnData);
Upvotes: 1