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 & HelpOther Libraries › DJ Native Swing
Page Index Toggle Pages: 1
DJ Native Swing (Read 1694 times)
DJ Native Swing
Jan 17th, 2010, 7:23am
 
I'm trying to use DJ Native Swing (http://djproject.sourceforge.net/ns/) in a sketch, particularly at the moment the native File Dialogs (though I wouldn't mind getting the web browser to work later).  

One problem I have with it is that you need to NativeInterface.open(); in the Main().  I'm not sure how to do this.  Here is the error I get.

Quote:
***WARNING: Display must be created on main thread due to Cocoa restrictions.

Exception in thread "Animation Thread" java.lang.IllegalStateException: An error occurred while creating the SWT Display! On a Mac, the Native Interface can only be initialized from the main thread and the Java process needs to be started with the "-XstartOnFirstThread" VM parameter.


Code:
import chrriis.dj.nativeswing.swtimpl.components.JFileDialog.*;

void setup() {
size(800,600);
NativeInterface.open();
NativeSwing.initialize();

//The file dialog supports multiple selection and extension filters. Here is such an example (an "open file" dialog):

JFileDialog fileDialog = new JFileDialog();
fileDialog.setSelectionMode(SelectionMode.MULTIPLE_SELECTION);
// We want 3 extension filters, and want the second choice (index 1) to be the default.
fileDialog.setExtensionFilters(
new String[] {
"*.*", "*.mp3;*.avi", "*.txt;*.doc" }
,
new String[] {
"All files", "Multimedia file (*.mp3, *.avi)", "Text document (*.txt, *.doc)" }
,
1);
fileDialog.show(this);
System.out.println("You selected: " + Arrays.toString(fileDialog.getSelectedFileNames()));
}
Re: DJ Native Swing
Reply #1 - Jan 17th, 2010, 2:59pm
 
You risk to have conflicts with the Processing threading scheme, it seems to mix badly with Swing in general.
But well, you can try and put your open() call in the void init() {} method (finish it with a call to super.init();).
Page Index Toggle Pages: 1