We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Trouble with noLoop() and swing or selectFolder()
Page Index Toggle Pages: 1
Trouble with noLoop() and swing or selectFolder() (Read 515 times)
Trouble with noLoop() and swing or selectFolder()
Aug 17th, 2008, 6:56pm
 
Hi,

I've been working on a program which loads in large data files of the user's choosing during run-time.  As these files can be quite large and take several minutes to load, I've been trying to use Swing's ProgressMonitor class to display a progress bar.  This works fine as long as the code is set to loop, however if I use noLoop() (which I want to for processor performance reasons) the ProgressMonitor will show up blank on the second use.  I've created a small demo to show what I mean:

Quote:


import javax.swing.ProgressMonitor;

void setup() {
 size(200,200);
 
 loadThing();
 
 //noLoop(); //this causes the issue
}

ProgressMonitor prog = new ProgressMonitor(frame, "test","",0,2000);

void loadThing() {
 //String loadPath = selectFolder(); //uncomment this for another error when noloop uncommented
 
 int t0 = millis();
 prog.setMinimum(t0);
 prog.setMaximum(t0+4000);

 while (millis() < t0+4001) {
   prog.setProgress(millis());
 }
}

void draw() {
 rect(50,50,100,100);  
}

void keyPressed() {
 loadThing();  
}




When running this in Processing, the first progress bar will work fine, however the second progress bar (initiated by pressing any key) will only display properly when noLoop() is not set.  Note that it will operate properly and it will disappear after the 4 seconds it takes for its simulated load, however the graphics and cancel button will be absent.

Another issue I've stumbled upon (however I can work around by using custom Swing code instead of the new command) is that when noLoop() is set, you cannot call the new file chooser commands like selectFolder().  This can be seen by uncommenting the line above and seeing the resulting error.

Does anyone know a method to work around either of these issues while keeping the code operating in noLoop() mode?  Any help is appreciated!

(P.S.  What happened to "Copy for Discourse" in newer versions of Processing?  I had to open the code in an older version to post this.)
Re: Trouble with noLoop() and swing or selectFolde
Reply #1 - Aug 17th, 2008, 8:28pm
 
All Swing calls must happen from the Event Dispatch Thread (EDT). Use SwingUtilities.invokeLater() to properly queue things so that they don't lock up. This is a Swing issue and can be very tricky, so I strongly recommend reading up on how Swing, the EDT, thread, and invokeLater() all work before you try to integrate any Swing code with Processing.

(Copy for Discourse is now under Edit, next to Copy.)
Page Index Toggle Pages: 1