• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing components won't repaint

 
Jim Follen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a great suggestion! I had not previously known the JTable setModel() method. It works fine now.

Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic