wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes repainting of components not running after jdialog opened Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "repainting of components not running after jdialog opened" Watch "repainting of components not running after jdialog opened" New topic
Author

repainting of components not running after jdialog opened

Gabriel Pelmus
Greenhorn

Joined: Oct 31, 2012
Posts: 2
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
Gabriel Pelmus
Greenhorn

Joined: Oct 31, 2012
Posts: 2
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

Joined: Jun 19, 2010
Posts: 825
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: repainting of components not running after jdialog opened
 
Similar Threads
Making Typing "Game", any tips or pointers before I start?
JOptionPane Timeout
Layout manager problem (horizontal & vertical boxes)
New Approach to GridLayout problem, but still having compiling problems
problem in printing swing components?