swingworker

Discard all messages except the last one in a Scala actor

夙愿已清 提交于 2019-12-06 15:26:38
I have a SwingWorker actor which computes a plot for display from a parameters object it gets send; then draws the plot on the EDT thread. Some GUI elements can tweak parameters for this plot. When they change I generate a new parameter object and send it to the worker. This works so far. Now when moving a slider many events are created and queue up in the worker's mailbox. But I only need to compute the plot for the very last set of parameters. Is there a way to drop all messages from the inbox; keep the last one and process only that? Currently the code looks like this val worker = new

SwingWorker updating multiple comboboxes in multilpe panels

淺唱寂寞╮ 提交于 2019-12-06 05:29:52
I have a little gui program that on startup reads data from an Excel file and some of these data need to go to the relevant comboboxes. I know how to do this by using a separate SwingWorker for each combobox: public class ExcelReader extends SwingWorker<DefaultComboBoxModel, String> { private final DefaultComboBoxModel model; // Constructor called from a panel that has a combobox public ExcelReader(DefaultComboBoxModel model) { this.model = model; } @Override protected DefaultComboBoxModel doInBackground() throws Exception { ///// code to read data from Excel file ///// publish(someString)

Update UI using swingworker thread

╄→尐↘猪︶ㄣ 提交于 2019-12-06 04:40:46
问题 I want to use the swing worker thread to update my GUI in swing. pls any help is appreciated.I need to update only the status of 1 field using the thread i.e setText(). 回答1: I just answer similar question on another forum for a question about SwingWorker: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import javax.swing.AbstractAction; import javax.swing.Action; import javax

Scheduling Swingworker threads

折月煮酒 提交于 2019-12-06 04:09:45
I have a 2 processes to perform in my swing application, one to fill a list, and one to do operations on each element on the list. I've just moved the 2 processes into Swingworker threads to stop the GUI locking up while the tasks are performed, and because I will need to do this set of operations to several lists, so concurrency wouldn't be a bad idea in the first place. However, when I just ran fillList.execute(); doStuffToList.execute(); the doStuffToList thread to ran on the empty list (duh...). How do I tell the second process to wait until the first one is done? I suppose I could just

Should i use SwingUtilities.invokeLater() inside of SwingWorker.doInBackground()?

为君一笑 提交于 2019-12-06 03:10:55
问题 The common way to interact with EDT from swing worker is useing get() method. But i have a long task and code like this: public Void doInBackground() { for(Object o : objects) { doSomething(); MyGlobalGUIConsole.addMessage("Done for " + o); } } In most tutotials is recommended to use return values to get something back from SwingWorker to EDT, but can i just: public Void doInBackground() { for(Object o : objects) { doSomething(); SwingUtilities.invokeLater(new Runnable() { @Override public

How can I report progress from a background task?

时间秒杀一切 提交于 2019-12-05 18:00:17
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. Normally I would use SwingWorker, but I'm working with a Java/Groovy backend for a Grails app, and I'm unsure how that would behave in a headless server environment since it has EDT ties. Another example is the Jobs framework in Eclipse RCP, but I would need

JDK-7 SwingWorker deadlocks?

无人久伴 提交于 2019-12-05 15:41:24
I have a small image processing application which does multiple things at once using SwingWorker. However, if I run the following code (oversimplified excerpt), it just hangs on JDK 7 b70 (windows) but works in 6u16. It starts a new worker within another worker and waits for its result (the real app runs multiple sub-workers and waits for all this way). Did I use some wrong patterns here (as mostly there is 3-5 workers in the swingworker-pool, which has limit of 10 I think)? import javax.swing.SwingUtilities; import javax.swing.SwingWorker; public class Swing { static SwingWorker<String, Void>

GUI not updating visually before running ActionEvent

橙三吉。 提交于 2019-12-05 08:44:31
To expound a little more, I have a GUI that looks like: Then I have an action listener on the OK button that starts like: //OK Button Action Listener private void okButtonActionPerformed(ActionEvent e) { //Enable/Disable Buttons okButton.setEnabled(false); cancelButton.setEnabled(true); updateCheckbox.setEnabled(false); //Move on to a series of other methods here... Which should, in theory, make this happen: However, instead, I get the following until ALL methods and other things connected to the OK button are completed: This obviously can't happen, because the idea is to make the cancel

java swing worker thread to wait for EDT

本小妞迷上赌 提交于 2019-12-05 08:23:41
I've got a worker thread that should wait for EDT to update the GUI before continuing execution. I've used the publish method to tell EDT to change something. How can i make the worker wait for that change to take place? If it is also your same worker thread that is initiating the GUI changes, then there's a ready-built mechanism for waiting for those changes to be made: SwingUtilities.invokeAndWait() should fit the bill nicely. Another alternative would be to use SwingUtilities.invokeLater() to give the EDT some code to run which will wake your thread up once the EDT becomes idle, i.e. when

How can I pass arguments into SwingWorker?

偶尔善良 提交于 2019-12-05 07:19:11
I'm trying to implement Swing worker in my GUI. At the moment I have a JFrame containing a button. When this is pressed it should update a tab displayed and then run a program in the background thread. Here is what I have so far. class ClassA { private static void addRunButton() { JButton runButton = new JButton("Run"); runButton.setEnabled(false); runButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ClassB().execute(); } }); mainWindow.add(runButton); } } class ClassB extends SwingWorker<Void, Integer> { protected Void doInBackground() { ClassC