1. Create JavaFX Application
project In IntelliJ.
2. Right click on project folder, then click Add Framework Support...
3. In the dialog window, choose Maven, hit OK
4. Edit pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>HelloFX</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>11.0.2</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.compiler.source>11.0.2</maven.compiler.source>
<maven.compiler.target>11.0.2</maven.compiler.target>
<openjfx.version>13.0.2</openjfx.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>icm</id>
<name>icm</name>
<url>http://maven.icm.edu.pl/artifactory/repo/</url>
</repository>
<repository>
<id>geo</id>
<name>geo</name>
<url>http://maven.geomajas.org/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx</artifactId>
<version>${openjfx.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${openjfx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${openjfx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>${openjfx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
5. Edit Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.File;
import java.net.URL;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
URL url = new File("src/main/java/sample/sample.fxml").toURI().toURL();
Parent root = FXMLLoader.load(url);
primaryStage.setTitle("Hello World");
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
6. Edit sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<FlowPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-padding: 5;" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<Button fx:id="btn_click_me" mnemonicParsing="false" onAction="#btnClickMeOnAction" text="Click Me" />
<Label fx:id="lblInfo" />
</FlowPane>
7. Edit Controller.java
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
public class Controller {
@FXML
private Label lblInfo;
@FXML
void btnClickMeOnAction(ActionEvent actionEvent) {
lblInfo.setText("Hello World");
}
}