Using JavaFX for your IB Computer Science IA

If you are comfortable using IntelliJ with/without Gradle or Maven then fine, but I find that sometimes these tools mask what is going on behind the scenes. For that reason, I often like to use a simple text editor for small projects. To get JavaFX working without a build manager, follow these simple instructions.

Download a version of JavaFX. I downloaded the Linux SDK (version 12) from here: https://gluonhq.com/products/javafx/

Unzip it to a place on your file system that you use to store java libraries. I just put mine in my home directory.

Create Main.java with the following code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {
    public void start(Stage stage) {
        Scene scene = new Scene(new Label("Foo"));
        stage.setScene(scene);
        stage.show();
    }
}

 
In order not to have to make changes to your CLASSPATH you can add arguments to the compiler and the JVM.

Compile with

javac --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main.java

Run with

java --module-path ~/javafx-sdk-12.0.2/lib --add-modules javafx.controls Main

Other modules may be required as you use more features of JavaFX.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s