Hey there,
My JDK is OpenJDK 11
I am using a Mac M1 (ARM64) so I got the corresponding swt JAR file for my program.
When i run my code, it does not open the display.
This is my code
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Main {
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setText("Hello World");
shell.setSize(500, 500);
shell.open();
shell.layout();
shell.forceActive();
}
}
and whether I run it in my IDE or via the command:
java -XstartOnFirstThread -classpath /Users/nugget1/git/testswt/out/production/testswt:/Users/nugget1/swt.jar Main
It does not open the display.
When I remove the -XstartOnFirstThread option and run the command, I get a stack trace error which says that I need it
it says:
***WARNING: Display must be created on main thread due to Cocoa restrictions. Use vmarg -XstartOnFirstThread
Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4893)
at org.eclipse.swt.SWT.error(SWT.java:4808)
at org.eclipse.swt.SWT.error(SWT.java:4779)
at org.eclipse.swt.widgets.Display.error(Display.java:1100)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:851)
at org.eclipse.swt.widgets.Display.create(Display.java:835)
at org.eclipse.swt.graphics.Device.<init>(Device.java:130)
at org.eclipse.swt.widgets.Display.<init>(Display.java:734)
at org.eclipse.swt.widgets.Display.<init>(Display.java:725)
at org.eclipse.swt.widgets.Display.getDefault(Display.java:1434)
at Main.main(Main.java:6)
Any help would be much appreciated...
Thanks