Configuring JavaFX Development on Linux-Ubuntu (Updated)
Preface I'm not sure why, but there is very little Chinese material about JavaFX online, and it's all quite old, so I suggest that those interested in learning JavaFX would be better off reading the official documentation. Also, it seems some people don't think highly of JavaFX. There's actually a lot more material about Swing. I find that rather strange—from a design perspective, JavaFX is more sophisticated, isn't it? PS: After nearly a week of tinkering and exploring, I found that using JavaFX with OpenJDK really has a lot of pitfalls~ The configuration of OpenJDK and Oracle JDK is different; here rec
目录7 个章节
Preface
I'm not sure why, but there is very little Chinese material about JavaFX online, and it's all quite old, so I suggest that those interested in learning JavaFX would be better off reading the official documentation. Also, it seems some people don't think highly of JavaFX. There's actually a lot more material about Swing. I find that rather strange—from a design perspective, JavaFX is more sophisticated, isn't it?
PS: After nearly a week of tinkering and exploring, I found that using JavaFX with OpenJDK really has a lot of pitfalls~ The configuration of OpenJDK and Oracle JDK is different; I recommend using Oracle JDK to avoid running into weird pitfalls~
Here's How to Install Oracle JDK
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
OpenJDK Requires One Extra Step
Because OpenJDK 8 does not include the JavaFX package by default, you need to install OpenJFX first.
Configuration
Open IDEA; in a regular Java project, importing the JavaFX package won't find it. When creating a Java project, IDEA does not import the JavaFX package by default, so we need to find the path ourselves and import it.
Open Project Structure, select SDKs, and you can see the JDK path.

Click the “+” sign next to it, then in the JDK directory, find the jfxrt.jar package in the /lib/ext folder and import it, and you're good to go~
HelloWorld
The first program starts with HelloWorld!
package lin.Learning.JavaFx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.control.Label;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Label label = new Label("the first label");
// 创建面板作为根节点
StackPane rootNode=new StackPane();
// 将label控件添加到根节点上
rootNode.getChildren().add(label);
// 创建场景对象,指定根节点对象和大小
Scene scene=new Scene(rootNode,200,60);
primaryStage.setTitle("Hello JavaFx");
// 将场景添加到舞台中
primaryStage.setScene(scene);
// 显示舞台
primaryStage.show();
}
}
Running result:

And with that, you've completed your first JavaFX program development on Linux.
Installing Scene Builder
A distinctive feature of JavaFX is the separation of View and Controller, using FXML to write the UI layout, and Oracle provides a WYSIWYG UI design tool, though you have to install it yourself.
Just download the version for your system; here I chose the Debian deb package.

For installing Scene Builder, you can refer to Oracle's documentation: https://docs.oracle.com/javase/8/scene-builder-2/installation-guide/preface.htm#sthref2
Here's an excerpt from the documentation about installing Scene Builder on Linux:
(Linux platform) Extract the Scene Builder 2.0 files from the javafx_scenebuilder-2_0-linux-<platform>.tar.gz to a directory on your local file system, or double-click the javafx_scenebuilder-2_0-linux-<platform>.deb file to open it with Ubuntu Software Center, where <platform> is either x64 or i586. By default, the Scene Builder application is installed at /opt/JavaFXSceneBuilder2.0/.
As you can see, the Scene Builder installation directory is: /opt/JavaFXSceneBuilder2.0/
Next, we need to configure it in IDEA.
IDEA Configuration
Open Settings

Configure the path

Then add an FXML file to our project.
Right-click and you can open it with Scene Builder; the interface is pretty nice.

_EOF_
Configuring JavaFX Development on Linux-Ubuntu (Updated)
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
深入Jar包:Gradle构建可执行jar包与访问jar包中文件夹与文件
前言 Java的跨平台功能听起来很诱人可口,号称“Write Once,Run Everywhere”,实际上是“Run Once,Debug Everywhere”... 在实际开发过程中还是会遇到各种各样的坑的,刚刚解决了一系列问题,特地写个文章总结一下。 使用Gradle构建Jar包 感谢万能的Gradle,极大提高了Java开发的生产力~ 在Gradle中生成jar包可以使用官方的插件:a
2022-05-27 · Java · 约 1 分钟
Java开发:JDK安装和环境配置
前言 环境配置是开发中最基础的部分,不过最近有很多新入坑的同学,都在问怎么安装JDK和配置环境,索性写一篇。 这里要注意一下,在Windows平台和Linux平台下做开发是不同的,Windows平台开发Java需要自己手动配置JDK的环境变量,而大多数Linux都是不需要的,安装了OpenJDK就可以了(可能很多发行版都自带了OpenJDK),这点是比较方便的。 下载Java JDK Window
2023-02-08 · Java · 约 1 分钟
Spring-Boot:创建第一个应用
简介 Spring Boot 是一个轻量级框架,可以完成基于 Spring 的应用程序的大部分配置工作。在本教程中,将学习如何使用 Spring Boot 的 starter、特性和可执行 JAR 文件结构,快速创建能直接运行的基于 Spring 的应用程序。 本文使用IDEA作为开发工具,Gradle作为构建工具,创建一个简单的SpringBoot应用,暂时不涉及数据库的配置。 使用IDEA创建
2022-05-27 · Java · 约 1 分钟
Apache-Commons-IO-最佳实践
本文列举了Java输入输出部分(IO area)的大量“最佳实践”(best practices)。 java.io.File 通常你需要去处理文件或文件名时,有许多会出错的情况: 一个类可在Unix运行但不能在Windows运行,反之亦然。 由于双路径分隔符(path separator)或缺失路径分隔符(path separator)导致文件名无效。 (在Windows上的)符合通用命名标准(
2022-05-27 · Java · 约 1 分钟
讨论
共 0 条加载评论中…