"A revolutionary period starting with everyone's Java OpenJDK! I somehow tried Getting Started with JavaFX with JavaFX 11 of Liberica JDK 11 so I'll take a note.
Most OpenJDK distributions do not include JavaFX (OpenJFX). So, if you follow the procedure of Getting Started with JavaFX obediently, it will take some time. However, if you install Liberica JDK 11 with SDKMAN !, you can easily play with JavaFX 11.
Install Liberica JDK 11 with SDKMAN!. Note that some versions do not include JavaFX. You can check the list of Java versions that can be installed with the sdk list java
command.
$ sdk install java 11.0.6.fx-librca
Save the following code with the file name HelloFX.java. It seems that I get the Java and JavaFX versions, generate a Label control with the string including it, and place it in the StackPane layout for display.
HelloFX.java
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 {
@Override
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Now let's compile and run it. Be sure to make sure that Liberica JDK 11 is set in SDKMAN !. If it is not set, execute the sdk use java 11.0.6.fx-librca
command, and then execute the following command.
$ sdk current java
Using java version 11.0.6.fx-librca
$ javac HelloFX.java
$ java HelloFX
Success if such a screen is displayed.
I often think that it will be distributed as an application, but if you want a simple GUI with in-house tools, JavaFX using Liberica JDK 11 seems to be useful.
This time, I tried Hello World with JavaFX 11 (OpenJFX) of Liberica JDK 11. When it comes to building a proper development environment, IntelliJ IDEA and Scene Builder should be used. I just took a look, but "The Definitive Guide to Modern Java Clients with JavaFX" described the procedure for building such a development environment.
A revolutionary period starting with everyone's Java OpenJDK! The Definitive Guide to Modern Java Clients with JavaFX
Recommended Posts