1

Initially I want jtable with one row, when I enter the last row, new row will create with the same format of previous row. Is it possible in jtable or any other options are available in java?

Tom
  • 16,842
  • 17
  • 45
  • 54
  • 3
    [`DefaultTableModel`](http://docs.oracle.com/javase/7/docs/api/javax/swing/table/DefaultTableModel.html) supports adding rows dynamically, but you can create your own `TableModel` to do it as well (which is typically more functional). Take a look at [How to Use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) for more details – MadProgrammer May 29 '15 at 09:29
  • For [example](http://stackoverflow.com/questions/23485987/how-to-add-items-to-a-jtable-using-a-loop/23486044#23486044) and [example](http://stackoverflow.com/questions/30117334/i-want-to-update-table-when-button-is-clicked/30117380#30117380) and [example](http://stackoverflow.com/questions/16785982/how-to-refresh-data-in-jtable-i-am-using-tablemodel/16786120#16786120) – MadProgrammer May 29 '15 at 09:31

1 Answers1

1

Use DefaultTableModel for your table. This provides you addRow method which can be used to add rows dynamically.

Using DefaultTableModel:

DefaultTableModel dtm = new DefaultTableModel(0, 0);
// Create your table column headers
    String header[] = new String[] { "Column1", "Column2", "Column3" };
    dtm.setColumnIdentifiers(header);

Now create Rows dyamically using addRow api

Vector<Object> data = new Vector<Object>();
        data.add("Data1");
        data.add("Data2");
        data.add("Data3");
dtm.add(data);

Hope this will help..

Kailas
  • 807
  • 1
  • 6
  • 20
  • 1
    ya finally i got the solution from Kailas concepts, my code is Here: DefaultTableModel tmodel = (DefaultTableModel) table.getModel(); tmodel.addRow(temp); Thank you for your valuable solutions. –  Jun 03 '15 at 05:45