swingworker

How to wait for object creation in EDT without blocking EDT?

I am using an API in a Java library which is called from the event dispatch thread and requires me to return a fully-initialized UI component. It looks like this: public JDialog createDialog(); But I can only populate the dialog after loading from a database, which can take 10 seconds sometimes. Normally I would do that in a backgrou...

How can I report progress from a background task?

I have a long running task that is executing in the background on an ExecutorService thread pool. What are some best practices in terms of this task returning progress or intermediate results? Are there any libraries that provide this functionality? EDIT: To clarify, I'm talking about reporting progress to other code, not to the user....

Java GUI and Multiple Instances of the SwingWorker Class

I'm making a GUI using Java (who isn't?). I know the Swing Worker class enables computation in the background to prevent the GUI from hanging, but I was wondering if there could be too much of a good thing here... For instance, if there were too many instances of those background threads running, would it impact the performance of th...

Printing output of another program to a java text area

I am creating a GUI using Java. This GUI launches a program from the command line using the ProcessBuilder class. A little information on the process being launched: from the command line, it creates another window and prints information to said window. In my GUI window, I have a text area to where I would like to redirect said ou...

Applet crashes when redirecting to a new url

Hi all, I'm developing an applet that makes some work and then a redirection to an URL when user clicks on a button. I'm using a SwingWorker to prevent GUI gets locked up. But when I run the applet I get this error after clicking the button: Exception in thread "SwingWorker-pool-1-thread-2" java.lang.IllegalMonitorStateException ...

ability to get the progress on a Future<T> object

With reference to the java.util.concurrent package and the Future interface I notice (unless I am mistaken) that the ability to start a lengthy tasks and be able to query on the progress only comes with the SwingWorker implementing class. This begs the following question: Is there a way, in a non-GUI, non-Swing application (imaging a c...

Make GUI more responsive

The program I have visualizes a physics simulation (basically). Right now, it works, but can get very unresponsive, and I think I know why - too much (read:all) computation is done on the event thread. When the 'play' button is pressed, a Swing Timer is created that wakes up periodically and calls updateTime() - so far so good. The pr...

Does SwingWorker has to be a nested class?

Hi there. I'm wondering if SwingWorker has to be a nested class within my main GUI. I'd rather make it an external class to keep the GUI clear from any of my programs logic. I tried to make the SwingWorker class external, which works fine for the process, unfortunately I can't access any of my GUI fields from the SwingWorker class. When...

Use SwingWorker to add rows to jTable and update the GUI

I'm trying to create a jTable that, once a button is clicked, adds rows one at a time with just a number starting at zero and continues adding rows until it gets to row 1000000. I'm using a SwingWorker's doInBackground, publish and process methods to increment the row counter and and add each row, which means the gui doesn't freeze while...

Timeout a task with Java's SwingWorker

I am trying to implement a SwingWorker class within my application. Is there a way to set a length of time that after which, the SwingWorker "times out"? I was thinking that maybe throwing an OutOfTime exception that I can catch and then deal with. I'm just not sure how to implement it. Thanks for all your help! ...

Force a subclass to implement abstract subclass

I want to create an abstract class in java that forces all its subclasses to implement a SwingWorker (plus the SwingWorker's abstract doInBackground() and done()). In AbstractClass - abstract class Task extends SwingWorker<Void, Void>{}; I would expect this to cause the compiler to throw an exception when an extended class doesn't im...

Swing: what to do when a JTree update takes too long and freezes other GUI elements?

Hello, everyone! I know that GUI code in Java Swing must be put inside SwingUtilities.invokeAndWait or SwingUtilities.invokeLater. This way threading works fine. Sadly, in my situation, the GUI update it that thing which takes much longer than background thread(s). More specific: I update a JTree with about just 400 entries, nesting de...

Java Swingworker: Not as encapsulated class

I'm having problems passing information, updating progress and indicating "done" with a SwingWorker class that is not an encapsulated class. I have a simple class that processes files and directories on a hard drive. The user clicks on the Start button and that launches an instance of the SwingWorker. I would like to print the nam...

Swingworker producing duplicate output/output out of order?

What is the proper way to guarantee delivery when using a SwingWorker? I'm trying to route data from an InputStream to a JTextArea, and I'm running my SwingWorker with the execute method. I think I'm following the example here, but I'm getting out of order results, duplicates, and general nonsense. Here is my non-working SwingWorker: c...

Java - SwingWorker - problem in process() method

I am using javax.swing.SwingWorker for the first time. I want to update a JLabel from the interim results published by the swing worker as follows: publish("Published String"); Now to update the JLabel, I have coded the following: process(List<String> chunks) { if (chunks.size() > 0) { String text = chunks.get(chunks.siz...

How to manage the default Java SwingWorker thread pool?

I've got an application that uses 2 long-running SwingWorker tasks and I've just encountered a couple of Windows computers with updated JVMs that only start one of the them. There are no errors indicated so I have to assume that the default thread pool has only a single thread and therefore the second SwingWorker object is getting queue...

how to return a list using SwingWorker

I have an assignment where i have to create an Image Gallery which uses a SwingWorker to load the images froma a file, once the image is load you can flip threw the image and have a slideshow play. I am having trouble getting the list of loaded images using SwingWorker. This is what happens in the background it just publishes the resul...

Java - SwingWorker - problem

I am developing a Java Desktop Application. This app executes the same task public class MyTask implements Callable<MyObject> { in multiple thread simultaneously. Now, when a user clicks on a "start" button, I have created a SwingWorker myWorker and have executed it. Now, this myWorker creates multiple instances of MyTask and submits t...

Java - SwingWorker - Can we call one SwingWorker from other SwingWorker instead of EDT

I have a SwingWorker as follows: public class MainWorker extends SwingWorker(Void, MyObject) { : : } I invoked the above Swing Worker from EDT: MainWorker mainWorker = new MainWorker(); mainWorker.execute(); Now, the mainWorker creates 10 instances of a MyTask class so that each instance will run on its own thread so as to ...

Java - Difference between SwingWorker and SwingUtilities.invokeLater()

SwingWorker is used for the following purposes: For running long-running tasks in a different thread so as to prevent the GUI from being unresponsive For updating GUI with the results produced by the long-running task at the end of the task through done() method. For updating GUI from time to time with the intermediate results produced...