I've been following instructions to build a Hello World JavaFX application using Java JDK 15 and JavaFX 15. I've added a run configuration described here: https://openjfx.io/openjfx-docs/#IDE-Eclipse . When I run the program on my Mac I receive no errors in my console but the GUI does not appear. Building the same application on my Windows computer I am able to build and see the GUI.
Main.java
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>
The solution to this problem can be found here .
Go to Run Configurations for the main class, and on the "Arguments" tab, uncheck the box where it says "Use the -XstartOnFirstThread argument when launching with SWT".
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.