简体   繁体   English

JavaFX使用Platform.runLater和SwingUtilities.involkeLater

[英]JavaFX using Platform.runLater and SwingUtilities.involkeLater

Would someone be able to give an example on using Platform.runLater and SwingUtilities.invokeLater with javaFX. 有人能够举例说明如何将Platform.runLater和SwingUtilities.invokeLater与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. 该类文件称为Window,但我不确定为什么要说Window $ 2,所以我认为$ 2是内存中的错误打印出来的垃圾。 The code I am using is below. 我正在使用的代码如下。 arguments is a static String[] since args is a not static. arguments是静态String [],因为args不是静态的。 Also, when I use launch(Window.class, arguments); 另外,当我使用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. 它引发错误,然后迅速消失,但是当我不包括Window.class时,它将根本无法工作。 Shouldn't it assume it is calling the launch method from the same class? 它不应该假设它正在从同一类中调用launch方法吗? Also, launch(args) works fine outside the methods. 另外,launch(args)在这些方法之外也可以正常工作。

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. SwingUtilities.involkeLater通常已过时,因为JavaFX打算替换Swing。 Platform.runLater unneeded, as launch may be called automagically. 不需要Platform.runLater,因为可以自动调用启动。

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 . 如果您没有key = value参数,请从Parameters中检查其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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