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

Help on SwingWorker  RSS feed

 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I wanted to understand the way SwingWorker is used. All i know is that it is used to perform some task in the background thread so that the GUI does not Freeze. i want to know HOW-TO actually use the SwingWorker class.

To make my question a little more clear i will put forth a simple application where SwingWorker can be used (Correct me if this is not the right place to use SwingWorker). I Designed a Simple swing application that captures the screenshot & saves it in a jpg file on the Hard-Drive. The GUI freezes for a couple of seconds while the file is being written to the disk. To avoid this problem i can create a Thread which just does the task of writing the jpg-file on the disk in the background.

It would be great help, if any of the fellow-ranchers could throw some light on this issue.

Thanks in advance...
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what you have described I would stay with creating another thread as you did.
SwingWorker is a deeper step in complexity and seems to do well for things that are complex enough to warrant a separate class. Here are a few examples I found with search: one, two and three.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!