Dear,
I am writing an application using Processing PApplet inside a Swing gui and those two are not a happy marriage. I have a listener for JButton which starts a Swing Worker to run some long calculations and then plot the outcomes. The problem is that only the calculations run in Swing Worker not the Processing Animation Thread responsible for plotting, in the result the gui looks like unoccupied (progress bar and Jbutton generateProcessing are not busy), while in reality it is still plotting for a good minute or so.
When profiling the application I can see Swing Worker thread running the calculations, then it dies out and the done() methods is executed and prints "Finished" message to terminal, then the Animation Thread immediately kicks in (after the plot is ready it doesn't go off but goes to sleep, but that's fine I guess).
The expected behaviuor would be to have the done() method called when both Animation Thread and the Swing Worker jobs are done.
My listener looks like this (timeSlicerToProcessing is a class extending PApplet)
I am writing an application using Processing PApplet inside a Swing gui and those two are not a happy marriage. I have a listener for JButton which starts a Swing Worker to run some long calculations and then plot the outcomes. The problem is that only the calculations run in Swing Worker not the Processing Animation Thread responsible for plotting, in the result the gui looks like unoccupied (progress bar and Jbutton generateProcessing are not busy), while in reality it is still plotting for a good minute or so.
When profiling the application I can see Swing Worker thread running the calculations, then it dies out and the done() methods is executed and prints "Finished" message to terminal, then the Animation Thread immediately kicks in (after the plot is ready it doesn't go off but goes to sleep, but that's fine I guess).
The expected behaviuor would be to have the done() method called when both Animation Thread and the Swing Worker jobs are done.
My listener looks like this (timeSlicerToProcessing is a class extending PApplet)
- private class ListenGenerateProcessing implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
- // Executed in background thread
- public Void doInBackground() {
- generateProcessing.setEnabled(false);
- progressBar.setIndeterminate(true);
- //omitted
- timeSlicerToProcessing.setBurnIn(Integer
- .valueOf(burnInParser.getText()));
- timeSlicerToProcessing.Impute(); //lengthy computations
- timeSlicerToProcessing.init();
- return null;
- }// END: doInBackground()
- // Executed in event dispatch thread
- public void done() {
- System.out.println("Finished. \n");
- generateProcessing.setEnabled(true);
- progressBar.setIndeterminate(false);
- }// END: done
- };
- worker.execute();
- }
- }// END: ListenGenerateProcessing
1