简体   繁体   中英

JavaFX using Platform.runLater and SwingUtilities.involkeLater

Would someone be able to give an example on using Platform.runLater and SwingUtilities.invokeLater with javaFX. I have attempted to use both and I am receiving the message :

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Error: class Window$2 is not a subclass of javafx.application.Application at javafx.application.Application.launch(Unknown Source) at Window$2.run(Window.java:50) at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source) at com.sun.javafx.application.PlatformImpl$$Lambda$47/389777815.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source) at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source) at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

The Class file is called Window and I not sure why it is saying Window$2, I would assume the $2 is some garbage from the memory printing out on the error. The code I am using is below. arguments is a static String[] since args is a not static. Also, when I use launch(Window.class, arguments); it throws the error then disappears quick but when I don't include Window.class it does not work at all. Shouldn't it assume it is calling the launch method from the same class? Also, launch(args) works fine outside the methods.

public static void main (String[] args) {
    arguments = new String[args.length];
    System.arraycopy(args, 0, arguments, 0, args.length);

    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            launch(arguments);
        }
    }); 

    /*
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            launch(Window.class, arguments);
        }
    }); */
    //launch(args);
}

SwingUtilities.involkeLater is normally obsolete, as JavaFX intends to replace Swing. Platform.runLater unneeded, as launch may be called automagically.

Parameters can be fetched as follows:

    @Override
    public void init() {
        Parameters params = getParameters();
        Map<String, String> named = params.getNamed();
        System.out.println(named);
    }

If you have other than key=value parameters, check hte alternatives from Parameters .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM