Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[Swing][Thread] How to update the GUI in a bacground task  RSS feed

 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Swing app (with MVC pattern) with a Browser window that browses all my items of type Variantes, and a Variante edition form. Once i save the Variante (button Save in the edition form), i want to reload all my Variantes. But this takes quiet a lot of time. I would like to reload the variantes and update the GUI in a background task.

So far, here is my code for my save button



And BrowseVariantesAction.reloadBrowser is like this:

First we reload the data model, then we reload the view...
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on what JDK Version you are using there could be better ways but to solve with the least common then it should be as simple as placing the bulk of your blocking work in:

 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answer. So for example if i put my call to the server inside, it will allow the user to do other actions meanwhile?
I won't work on this right now cause i have higher priorities on my application...
Nicolas
 
Steven Wall
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option on Java 6 is to use the SwingWorker class.

There is a backport to Java 5 of this class available on Swing Labs.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!