Hi everybody,
I have a Jtable and i am going to add an empty row after pressing a button named insert.
Whenever i put these following code in my class ,it works properly.
I should add after these 2 lines i create a JScrollPane and add it to the getContentPane().

model = new DefaultTableModel(data,columnNames);   
    model.insertRow(table.getRowCount(),new Object[]  {"","","","",""});

Whenever i put these 2 lines in a seperate function like addRow() and call this function after pressing the insert button , i see no changes in Jtable,i mean a new empty row isn't added to the table.
I think i should add a new table to the JScrollPane but since i'm a new programmer in java ,i don't know how to do this.

Can anyone help me please?

9 Years
Discussion Span
Last Post by puneetkay


model = new DefaultTableModel(data,columnNames);   
    model.insertRow(table.getRowCount(),new Object[]  {"","","","",""});

When you use this code, It will create a new DefaultTableModel object and add blank row into it. But this model have NO association with table Nor Table is using this Model so row will not be added.

You should use :

model = JTableObj.getTableModel();   
    model.insertRow(table.getRowCount(),new Object[]  {"","","","",""});

getTableModel() method will return the Model object that is being used by table to display rows.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.