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 许可协议。转载请注明出处!
相关文章
Java开发:JDK安装和环境配置
前言 环境配置是开发中最基础的部分,不过最近有很多新入坑的同学,都在问怎么安装JDK和配置环境,索性写一篇。 这里要注意一下,在Windows平台和Linux平台下做开发是不同的,Windows平台开发Java需要自己手动配置JDK的环境变量,而大多数Linux都是不需要的,安装了OpenJDK就可以了(可能很多发行版都自带了OpenJDK),这点是比较方便的。 下载Java JDK Window
2023-02-08 · Java · 约 1 分钟
Java使用JDBC操作SQLite
SQLite介紹 SQLite是一個輕量級的資料庫系統,不需要安裝就可以使用,也可以十分容易的就內嵌於系統內,FireFox就內嵌SQLite,可以在FireFox上直接使用JavaScript來呼叫操作資料庫。 SQLite是由C語言撰寫而已,可以跨Linux及Windows等平台,在Java存取及操作上則可使用JDBC來連線SQLite。 在JDBC連線SQLite上,大概分成二種方式,一種是
2021-12-18 · 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 分钟
Maven国内镜像配置
配置maven安装目录下的conf/settings.xml。 在<mirrors>节点下,设置: mirror idaliyun-public/id mirrorOf*/mirrorOf namealiyun public/name urlhttps://maven.aliyun.com/repository/public/url /mir
2021-12-18 · Java · 约 1 分钟
讨论
共 0 条加载评论中…