简体   繁体   English

运行javafx应用程序时没有出现窗口

[英]No window comes up when running javafx application

Running JavaFX application using VM argument.使用 VM 参数运行 JavaFX 应用程序。 Program compiles and runs.程序编译并运行。 Using Eclipse on MacOS.在 MacOS 上使用 Eclipse。 When the program runs it shows the java coffee cup logo in the dock, but no window comes up.当程序运行时,它会在 Dock 中显示 java 咖啡杯徽标,但没有出现窗口。

I want to be able to run this program successfully.我希望能够成功运行这个程序。 I believe it's an Eclipse configuration issue rather than code.我相信这是一个 Eclipse 配置问题而不是代码。

I had a lot of issues getting JavaFX to run on Eclipse for Mac with the main one being that libraries did not exist and would not import.让 JavaFX 在 Eclipse for Mac 上运行时遇到了很多问题,主要问题是库不存在且无法导入。 I was able to get it to work by downloading JavaFX from here ( https://gluonhq.com/products/javafx/ ), creating a user defined library into my project and running the program with a VM argument: --module-path /Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib --add-modules=javafx.controls.我能够通过从这里下载 JavaFX ( https://gluonhq.com/products/javafx/ ),在我的项目中创建一个用户定义的库并使用 VM 参数运行程序来使其工作:--module-path /Library/Java/JavaVirtualMachines/javafx-sdk-11.0.2/lib --add-modules=javafx.controls。 Now the program compiles but I bump into the issue described above.现在程序可以编译,但我遇到了上述问题。

This post describes the issue I'm having: https://discussions.apple.com/thread/7886329这篇文章描述了我遇到的问题: https : //discussions.apple.com/thread/7886329

import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;

public class SimpleCalculator extends Application
{

    private Label firstValue;
    private Label secondValue;
    private Label sumLabel;

    public void start( Stage myStage) 
    {
        myStage.setTitle( "Simple Calculator");
        FlowPane rootNode = new FlowPane();        
        Scene myScene = new Scene( rootNode, 300, 200 );           

        Label firstValue = new Label( "First Value: ");            
        Label secondValue = new Label( "Second Value: ");          
        Label sumLabel = new Label( "Sum is: ");                   

        TextField firstField = new TextField();                    
        TextField secondField = new TextField();                   
        TextField sumField = new TextField();                      

        sumField.setEditable(false);                               

        rootNode.getChildren().addAll( firstValue, firstField, secondValue, secondField, sumLabel, sumField);
        myStage.setScene( myScene );                                                                                        
        myStage.show();                                                                                          
    }

    public static void main(String [] args)
    {
        launch( args );                                            
    }

}

Window pops and shows the labels and fields.窗口弹出并显示标签和字段。 This is not happening with my current code.我当前的代码不会发生这种情况。

I had this problem as did people associated with 3 other posts that I saw.我遇到了这个问题,与我看到的其他 3 个帖子相关的人也遇到了这个问题。

I disabled this option in run configurations of eclipse: Use the -XstartOnFirstThread argument when launching with SWT我在 eclipse 的运行配置中禁用了这个选项:使用 SWT 启动时使用 -XstartOnFirstThread 参数

It then worked perfectly然后它完美地工作

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

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