I can't seem to get my table to refresh. I created a refresh button that calls jTable1.repaint();
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)
// Reader Refresh
jTable1.repaint();
}
I also tried just recalling the RegistryValues
again in the button like RegistryValues.arp(null);
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt)
// Reader Refresh
RegistryValues.arp(null);
}
Also tried combining the registryvalues and repaint in the button.
Below is the code for my jTable
. The RegistryValues
are from another class that uses JNA to read the registry if that matters.
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"Protected Mode at Startup", RegistryValues.arp(null)},
{"Display PDF in browser", RegistryValues.arb(null)},
{"EULA Accepted?", RegistryValues.are(null)},
{null, null}
},
new String [] {
"Software", "Status"
}
));
Neither
jTable1.repaint();
or
RegistryValues.arp(null);
will actually refresh the table with new values. For this you need to either update the current table model or set a new model but in your ActionListener.
As you're using DefaultTableModel, which is mutable, you could create an update helper method for the model.
Something like:
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setValueAt(RegistryValues.arp(null), 0, 1);
// set more row data, etc.
Note: You could save the model as a class member variable and eliminate the need for casting.
来源:https://stackoverflow.com/questions/12078061/refresh-a-jtable