I have an application that has a JTable and a button. When I press the button a JDialog opens with some fields to enter data. When I close the dialog I want the data to populate the JTable. Although the data is saved in a DefaultTableModel variable using the .addRow() method, the view in the JTable does not update. Here is a sample of the code:
I can't understand why this is happening. Could someone please help me? Thanks!
I couldn't really go through your entire code right now, but what sticks out first is that you made all your methods static and that you have two GUIx classes but none of them extends JFrame or JDialog. I think you should refactor your code before you jump to anything else.
As for your question, try to invoke fireTableDataChanged() on your table model after you add new row, that's what usually causes the problem you have.
The quieter you are, the more you are able to hear.
Joined: Oct 31, 2012
Thanks for your reply! I'll try to refactor my code asap. I have a question though... Would it be normal for the table to show the data row without invoking the fireTableDataChanged() when the data is inserted using the .addRow() method in the ActionListener of a button on the same frame but not show the data when the .addRow() method is called from another frame or dialog? Also after I close the dialog or frame and click the button on the main frame to add one more row to the table, this new row isn't displayed either. Maybe I'm missing something but it seams to me that the dialog or frame isn't disposed properly and this blocks the repaint of the components in the main frame.
To be honest, that code is you posted is a real mess. I would suggest you start over and do it in small steps; when you encounter a problem, feel free to ask here.
The one you posted originally is not what you are talking about (just got a chance to review it in more detail). It can be compiled but once you run it you get NullPointerException (table model is not initialized, or at least I can't follow that train of thougths you put into your code), so I don't know how your original question was that table is not updating its view after you add a new row.