JavaFX
Download JavaFX (opens in a new tab) and extract it locally to {JAVAFX_PATH}
: /Users/user/javafx-sdk-24
, for example.
Code
-
Import JavaFX’s components (all the
*.jar
files underlib
) into your project as referenced libraries. This will update.vscode/settings.json
:.vscode/settings.json{ "java.project.sourcePaths": ["src"], "java.project.outputPath": "bin", "java.project.referencedLibraries": [ "lib/**/*.jar", "{JAVAFX_PATH}/lib/**/*.jar" ] }
-
Create
.vscode/launch.json
using theRun and Debug
view, then update your configuration with the following settings:.vscode/launch.json{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Application", "request": "launch", "mainClass": "App", "vmArgs": "--module-path {JAVAFX_PATH}/lib --add-modules javafx.controls" } ] }
-
Launch the newly created configuration by selecting it from the dropdown menu in the
Run and Debug
view then running it usingStart Debugging
(F5
).
IDEA
Follow the Create a new JavaFX project (opens in a new tab) guide from JetBrains.
Eclipse
Follow the Getting Started with JavaFX (opens in a new tab) guide from OpenJFX:
- Open the marketplace using
Help
→Eclipse Marketplace
then search for and install the e(fx)clipse (opens in a new tab) plugin. Agree to the license terms and wait—this will take a while—until you receive a message asking you to restart Eclipse to apply the update. - Select
Settings
→JavaFX
then specify the location of the JavaFX directory ({JAVAFX_PATH}
) inJavaFX 11+ SDK
. - Select
Settings
→Java
→Build Path
→User Libraries
then click onNew
to create a new user library namedJavaFX
. Click onAdd External JARs
and select all the*.jar
files under{JAVAFX_PATH}/lib
and add them. - Select
Project
→Properties
→Java Build Path
→Libraries
→Modulepath
thenAdd Library
→User Library
and selectJavaFX
. - Select
Settings
→Run/Debug
→String Substitution
and create a new variableFX_PATH
with the value{JAVAFX_PATH}/lib
. - Select
Run
→Run Configurations
→Java Application
→Arguments
, setVM Arguments
to--module-path ${FX_PATH} --add-modules javafx.controls
and uncheckUse the -XstartOnFirstThread argument when launching with SWT
.
Sample
Main.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) { launch(args); }
}