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

Problem Updating Content Of JTable

 
Navjot Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to JAVA and NetBeans. My problem is basically to dynamically update the contents of Jtable when an event (such as a button click occurs). I am using the following function to do the same in event handling function:

jTable1.setValueAt(celval, jTable1.getEditingRow(), jTable1.getEditingColumn());


I have verified the values returned by celval( A String) , getEditingRow (gives the row number of the selected cell.) , getEditingColumn(gives the column number of the selected cell).

But the problem is that setValueAt neither updates the cell value( I tried verifying by using getValueAt function) nor does it update the values being displayed in the GUI. Can anyone tell me how to correctly use this function.

The JTable is used here is has DefaultTableModel as its Model. ( Honestly, I dont know much about that, I just used NetBeans drag and drop. )

Am pasting the code as generated by NetBeans for this JTable.




Any help would be greatly appreciated.
Thanks!
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't make sense to me that the editing row/column would have valid values when you click a button because cell editing should be stopped. I would try the getSelectedRow/Column methods.

Post your SSCCE that demonstrates the problem.
 
Navjot Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets Simplifiy the problem to

jTable1.setValueAt("Some String",1,1)

every time a button is clicked.

Even this doesnt work correctly. ( My table has more than two rows and columns ) .
 
Navjot Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks Rob..Sorry for the last reply, I actually wrote that before trying. SetValueAt is working fine if i give some constant value.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic