Adding JavaFX to Eclipse in Java 11
Due to JavaFX's exclusion from Java 11, getting it up and running in Eclipse requires a specific setup. Here's a comprehensive guide:
Prerequisites:
Steps:
Add Java 11 JRE to Eclipse:
Navigate to Eclipse > Window > Preferences > Java > Installed JREs > Add and select the installed Java 11 JRE.
Create User Library for JavaFX:
Go to Eclipse > Window > Preferences > Java > Build Path > User Libraries > New. Name it JavaFX11 and add the jars from the lib folder of JavaFX 11-ea.
Create Java Project:
Create a new Java project, ensuring Java 11 is selected. Include the JavaFX11 library in its module path.
Add HelloFX Application:
Create a package named javafx11 and add the following Java class:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class HelloFX extends Application { public static void main(String[] args) { launch(); } @Override public void start(Stage stage) { Scene scene = new Scene(new StackPane(new Label("Hello, JavaFX 11")), 300, 200); stage.setScene(scene); stage.show(); } }
Add Runtime Arguments:
Edit the project's Run Configuration and add the following VM arguments:
Run the Project:
Run the HelloFX project, and it should display a simple message.
The above is the detailed content of How Can I Integrate JavaFX into Eclipse Using Java 11?. For more information, please follow other related articles on the PHP Chinese website!