I am trying to update a JTable from another JFrame without closing the main JFrame. The main JFrame has the JTable, the second JFrame has the text fields and the "update" button that get the data to update the JTable in the main window, everything works fine, but if I want the JTable to update correctly, I have to set the visibility of the main frame to "false" and change it to "true" when the "update" button completes the action, so, basically the main window its closed and after the update action is re-open. I want to know if there is any way to do the update without closing the main JFrame.
Button in the main frame that opens the second frame:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
UpdtFrame frame = new UpdtFrame();
frame.setVisible(true);
}
The button to update in the second JFrame:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Object[] info = {jTextField1.getText(), Double.parseDouble(jTextField2.getText()), Integer.parseInt(jTextField3.getText())}; //get the info from the text fields
updtProdList(jTextField1.getText(), info);
inter.setVisible(true); //object of the main JFrame, opens the frame after do the
//update
this.dispose();
}
The update operation:
public void updtProdList(String name, Object[] info)
{
for(int i = 0; i < inter.jTable1.getRowCount(); i++)
{
if(inter.jTable1.getValueAt(i, 0).toString().equalsIgnoreCase(name))
{
for(int j = 0; j < info.length; j++)
{
inter.jTable1.setValueAt(info[j], i, j);
}
break;
}
}
inter.jTable1.revalidate(); //update the table on the main frame
}
I don't know how to do the JTable update without closing the frame and opening it again, any help is appreciated.