gpt4 book ai didi

java - 在 Mac 上使用 Eclipse 在 JavaFX 15 中未显示 GUI

转载 作者:行者123 更新时间:2023-12-04 08:42:25 24 4
gpt4 key购买 nike

我一直在按照说明使用 Java JDK 15 和 JavaFX 15 构建 Hello World JavaFX 应用程序。我添加了此处描述的运行配置:https://openjfx.io/openjfx-docs/#IDE-Eclipse .当我在 Mac 上运行该程序时,我的控制台中没有收到任何错误,但没有出现 GUI。在我的 Windows 计算机上构建相同的应用程序我能够构建并查看 GUI。
主程序

package hellofx;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 400, 300));
primaryStage.show();
}


public static void main(String[] args) {
launch(args);
}
}
Controller .java
package hellofx;

import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class Controller {

@FXML
private Label label;

public void initialize() {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
label.setText("Hello, JavaFX " + javafxVersion + "\nRunning on Java " + javaVersion + ".");
}
}
hellofx.fxml
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.StackPane?>


<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="hellofx.Controller">
<children>
<Label fx:id="label" text="Label" />
</children>
</StackPane>

最佳答案

这个问题的解决方法可以在here找到.

Go to Run Configurations for the main class, and on the "Arguments"tab, uncheck the box where it says "Use the -XstartOnFirstThreadargument when launching with SWT".

关于java - 在 Mac 上使用 Eclipse 在 JavaFX 15 中未显示 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64493118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com