Using SwingWorker to run background process

The following example fetches Facebook data in a background process and passes the data to the GUI.

SwingWorker<User, String> fetchUserWorker = new SwingWorker<User, String>()
protected User doInBackground() throws Exception
IFacebookController controller = new RestFBController(accessToken);

User user = controller.fetchMe();

return user;

protected void done()
User user;
BackgroundProcess.this.mainGui.appendProgressLog("Fetched user record");

// get the user object from doInBackground()
user = get();
catch (InterruptedException | ExecutionException e)
BackgroundProcess.this.mainGui.appendProgressLog("ERROR fetching facebook data "+e.getMessage());


BackgroundProcess.this.mainGui.appendProgressLog("Fetch Current User - Connecting to Facebook");


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s