swingworker

java swing worker thread to wait for EDT

我是研究僧i 提交于 2019-12-10 05:24:28
问题 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? 回答1: 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

MVC - SwingWorker with a long running process that should update the view

被刻印的时光 ゝ 提交于 2019-12-09 12:11:33
问题 How to obtain separation of the View from model when using a SwingWorker with a long running process that should send updates back to the controller ? I can use the SwingWorkers doInBackground() to keep the EDT responsive by calling e.g model.doLongProcess() from in there great! The issue I have is trying to get data back before the process is finished, to update the view with the progress.. I know that I can get data back by using by using the SwingWorkers publish() method but this I think

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

牧云@^-^@ 提交于 2019-12-09 07:13:08
问题 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 complete the work faster. But the problem is I want to update the gui from time to time while the tasks are running. I know that if the task was executed by the mainWorker

Wait for a background process to end with SwingWorker from a different class

♀尐吖头ヾ 提交于 2019-12-08 05:45:40
问题 I'm importing a file to a project and once the user clicks select this file I do some things, including one through the command line. I had done it using this method: p = Runtime.getRuntime().exec(command, null, new File(directory)); p.waitFor(); As this process may take some time I decided to put a progress bar popup showing all the output of the current process in a new frame. I've followed this code from @trashgod adapted to my project. For the purpose of this question let's say I have it

SwingWorker updating multiple comboboxes in multilpe panels

会有一股神秘感。 提交于 2019-12-08 02:13:53
问题 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

SwingWorker, done() method not called

白昼怎懂夜的黑 提交于 2019-12-07 12:58:55
问题 This is, simply an implementation of SwingWorker: class GuiWorker extends SwingWorker<Integer, Integer> { private JFrame frame = new JFrame(); private JDialog dialog = new JDialog(frame, "Loadin data", true); private JProgressBar progressBar = new JProgressBar(); private Statistics st = new Statistics(); public GuiWorker(GraphEditor editor, Statistics st) { this.st = st; Window mainWindow = SwingUtilities.windowForComponent(editor .getGraphComponent().getParent()); dialog.setSize(400, 200);

How can I report progress from a background task?

£可爱£侵袭症+ 提交于 2019-12-07 08:45:58
问题 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

GUI not updating visually before running ActionEvent

旧城冷巷雨未停 提交于 2019-12-07 07:22:40
问题 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

SwingWorker hangs at Unsafe.park()

百般思念 提交于 2019-12-07 03:40:07
问题 I have a SwingWorker that communicates with a server in the background and then updates a JFrame . I was debugging my app and noticed that even after the SwingWorker finished its work, its thread still remained. It is hanging at Unsafe.park(java.lang.Object) which is a native method. I looked in to this further and found that all my other SwingWorker s in my app do the same thing after they finish. I can provide source code if someone wants it but I don't think it is necessary because the

How can I pass arguments into SwingWorker?

若如初见. 提交于 2019-12-07 03:29:00
问题 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