To add row to JTable
, one of the ways is:
1) Create table using DefaultTableModel:
DefaultTableModel model = new DefaultTableModel();
model.addColumn("Code");
model.addColumn("Name");
model.addColumn("Quantity");
model.addColumn("Unit Price");
model.addColumn("Price");
JTable table = new JTable(model);
2) To add row:
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.addRow(new Object[]{"Column 1", "Column 2", "Column 3","Column 4","Column 5"});