0% found this document useful (0 votes)
21 views4 pages

Instructions JavaFX

This document provides step-by-step instructions for setting up a JavaFX development environment using Sublime Text. It includes downloading the JavaFX SDK, creating a custom build system in Sublime Text, and writing a simple JavaFX application. Additionally, it explains how to create a batch file to easily compile and run JavaFX applications from the command line.

Uploaded by

begaly.adil1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Instructions JavaFX

This document provides step-by-step instructions for setting up a JavaFX development environment using Sublime Text. It includes downloading the JavaFX SDK, creating a custom build system in Sublime Text, and writing a simple JavaFX application. Additionally, it explains how to create a batch file to easily compile and run JavaFX applications from the command line.

Uploaded by

begaly.adil1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Download the JavaFX SDK from the official Oracle or OpenJFX website.

Unzip it to a
convenient location on your computer, for example.

a.
b. Please make sure that it’s not within the ZIP package.
2. Create new build system.
a. Open SublimeText
b. “Tools” -> Build System -> New Build System
c. Paste: {
"shell_cmd": "javac --module-path %PATH_TO_JAVAFX% --add-modules
javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \"${file}\" &&
java -cp \"${file_path}\" --module-path %PATH_TO_JAVAFX% --add-modules
javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \"$
{file_base_name}\"",

"file_regex": "^(..[^:]):([0-9]+):?([0-9]+)?:? (.)$",

"working_dir": "${file_path}",

"selector": "source.java",

"variants":

"name": "Compile",

"shell_cmd": "javac --module-path %PATH_TO_JAVAFX% --add-modules


javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \"${file}\""

},

{
"name": "Run",

"shell_cmd": "java -cp \"${file_path}\" --module-path %PATH_TO_JAVAFX% --add-modules


javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \"$
{file_base_name}\""

d. Instead of %PATH_TO_JAVAFX% write the path to JavaFX. In my case it is \"C:\\tools\\


javafx-sdk-19.0.2.1\"

e. Save the file as -> MyJavaFX.sublime-build.


f. Tools -> Build System -> Choose MyJavaFX.
3. Build the simple app to test it and save it:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class SimpleJavaFXApp extends Application {

public static void main(String[] args) {


launch(args);
}

@Override
public void start(Stage primaryStage) {
// Create a button
Button btn = new Button();
btn.setText("Click me");

// Set action on button click


btn.setOnAction(e -> System.out.println("Button Clicked!"));

// Add button to a layout


StackPane root = new StackPane();
root.getChildren().add(btn);

// Create a scene
Scene scene = new Scene(root, 300, 250);

// Set the scene to the stage and show it


primaryStage.setTitle("Simple JavaFX App");
primaryStage.setScene(scene);
primaryStage.show();
}

4. Now to easily run any new JavaFX app that you created, you need to do the last step:
a. Open new text file or just click to New File in Sublime text (Ctrl + N).
b. Paste this code:
@echo off
javac --module-path "C:\tools\javafx-sdk-19.0.2.1\lib" --add-modules
javafx.controls,javafx.fxml *.java
java --module-path "C:\tools\javafx-sdk-19.0.2.1\lib" --add-modules
javafx.controls,javafx.fxml %1
 Write your own path to javaFX folder.
 Don’t forget to add \lib

c. Save as -> runfx.bat (Note that it’s .bat format file). Save it where your projects are
located. For example:
d. Now write in such pattern: <bat file name> <class name>. When you will run it you
will see that it’s all running other classes, but you only have to worry about the your
class that you write after <bat file name>

You might also like