aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swing components won't repaint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing components won Watch "Swing components won New topic
Author

Swing components won't repaint

Jim Follen
Greenhorn

Joined: Jul 29, 2011
Posts: 8
Hello,

I am working on a Java plug-in that works fine except for a repainting (refreshing) problem. The plug-in pulls in some information from external source via a button click and populates correctly the first time through. However, when I try to refresh the data, the Swing components won't repaint. I've tried a number of different ways of coding this, but with no luck. Below is the class in question. There is another class that I have not included (FillTable) that simply provides the row/column logic for the data results set. Please see my code below:



Any insights as to why the GUI won't refresh would be appreciated. Thank you.

Jim
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

I see that you are creating new Swing components every time the button is clicked. Presumably (I haven't looked too closely) you're putting the data into them, but the original versions of the components are still the ones which are displayed. I don't think that creating new components on every button click is a good idea, even if you did remove the old ones and add the new ones. It makes much more sense to just update the components which are already there.
Jim Follen
Greenhorn

Joined: Jul 29, 2011
Posts: 8
Thanks for your response, that makes perfect sense. However, perhaps due to my being a relative novice in Swing, I'm not sure how to effect this change. Can you suggest how to modify this syntax if I created the new JTable outside of the createComponent() method? The current code is below:



The myModel method returns type FillTable...the other class not shown that extends AbstractTableModel. If I simply use , compilation fails with the error "Cannot convert FillTable to JTable". Any ideas what the syntax should be?

Thanks again for your help.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Create the JTable as part of the code which initializes the GUI. Then when you want the data in it to change, create a new table model and pass it to the JTable's setModel() method.
Jim Follen
Greenhorn

Joined: Jul 29, 2011
Posts: 8
That was a great suggestion! I had not previously known the JTable setModel() method. It works fine now.

Thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing components won't repaint