In Processing V2 the
selectInput method creates a new thread and uses
JFileChooser in the new thread. This leaves Processing to continue in the main thread and open the display window at the same time.
The only way round this is to use
JFileChooser in the main thread before
setup()finishes. There are 2 ways I know of
- Do not use selectMethod but rather write code in setup that uses JFileChooser directly.
- Use the G4P library since it provides methods to use JFileChooser in the main thread. This example comes with the library and demonstrates the dialogs available with G4P. The code below will keep opening the dialog box until a file is selected and only then open the display window.
- import g4p_controls.*;
- String fname;
- void setup() {
- size(600, 200);
- do {
- fname = G4P.selectInput("Input Dialog");
- }
- while (fname == null);
- }
- void draw() {
- background(255);
- fill(0);
- text(fname, 10, 40);
- }