Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add an editable row to an non editable JTable

 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any one knows how to add/insert an editable row to a non editable JTable?
My table populates data from a file and in order to add a new value i want an editable row added to the last in the JTable.
Can anyone help me out?

Thanks
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying setEnabled(false) has been set on the JTable?

if you want to add an extra line at the end of a JTable for input here is a code example:

String[] columns = {"Column One", "Column Two"};
String[][] data = {{"name", "1"}, {"name", "2"}, {"input row",""}};
javax.swing.table.TableModel model = new javax.swing.table.DefaultTableModel(data, columns);

model.setValueAt("YOUR INPUT VALUE", model.getRowCount() - 1, 1);

javax.swing.JTable table = new javax.swing.JTable(model);
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick,
Thanx for ur suggestion.Im not talking about setEnabled. The table is basically a non editable table,but the last row of the table should always be editable.

Any idea?

Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
shansi raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael..It works great!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic