I want to add row in a JTable consistently. I have two Frames. From the first frame I will take data like below-
(Frame 1)
And in the second frame I have made a JTable like-
(Frame 2)
I have added an actionListener in the first frame's "Submit" button like-
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
int a = 1, room = 301;
List li = new List();
DefaultTableModel model = (DefaultTableModel) List.table.getModel();
model.addRow(new Object[]{a++,name.getText(),mobile.getText(),ward.getText(),room++});
li.setVisible(true);
}
I could add a row successfully. But, the problem is when I add another Patient detail, It adds that data in a different frame and previous data vanishes itself. I don't know the cause as I doing this for the first time. I want to show this in list frame consistently.
I have tried to do this in the same frame, if I input data and click OK, It can add the row one by one, I searched in youtube and found this to do this in only one frame, when I want to do so in two separate frame, it don't add rows. It repaces the previous row only.
TableModel
to the second class, fill as desired; Use an Observer Pattern to get notifications from the "generator" class for when things have been "generated", fill table as desired; Use a Producer/Consumer Pattern, fill as desired; Use a dialog, fill in the details, when closed, as the dialog for the details and fill table as desired, see How to Make Dialogs for more details – MadProgrammer