jtable update data not visible
Posted
by
Thomas n
on Stack Overflow
See other posts from Stack Overflow
or by Thomas n
Published on 2012-07-07T03:11:38Z
Indexed on
2012/07/07
3:15 UTC
Read the original article
Hit count: 183
java
I am running into a problem similar to what I have read here about inserted data and added data not showing up on jtable. I have tried repaint() and revalidate(), but to no avail.
Basically, I have two classes say A and B. A calls a function in class B to add a row of data to the table. Here is the code.(By the way I am using Netbeans 7.1.2 to add a table and then add some code to handle the update.)
public void callUpdateTable(){
DefaultTableModel myModel = (DefaultTableModel)jTable1.getModel();
DateFormat dateFormate = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Object[] str = new Object[3];
Date date = new Date();
str[0] = dateFormate.format(date);
str[1] = "Robot";
str[2] = "hello";
// myModel.addRow(str);
myModel.insertRow(1, str);
myModel.setValueAt("Hello", 1, 2);
System.out.println("count = " + myModel.getValueAt(1, 2));
jTable1.repaint();
}
The funny thing is on system print it prints out the value at the cell(1,2) I set the value, but doesn't show up on the table. Thank you for your help.
© Stack Overflow or respective owner