Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repainting of components not running after jdialog opened

 
Gabriel Pelmus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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!
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gabriel Pelmus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic