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 许可协议。转载请注明出处!
相关文章
JavaWeb开发---使用IDEA创建Servlet程序
前言 最近做项目需要,从之前熟悉的PHP和Python转到了JavaWeb,所以就有了这个笔记。资源图片都是来自网上的资源,根据自己的实际操作应用,做了总结归纳。 所需工具 JDK Tomcat IDEA 创建工程 设置工程名字: 创建完成后工程结构如下: 上面的图片是在网络上复制的,好像我用的IDEA 2017.3.2没有这个Create web.xml的选项,我也不知道为啥,难道是IDEA越更
2021-12-18 · Java · 约 1 分钟
Spring-Boot:创建第一个应用
简介 Spring Boot 是一个轻量级框架,可以完成基于 Spring 的应用程序的大部分配置工作。在本教程中,将学习如何使用 Spring Boot 的 starter、特性和可执行 JAR 文件结构,快速创建能直接运行的基于 Spring 的应用程序。 本文使用IDEA作为开发工具,Gradle作为构建工具,创建一个简单的SpringBoot应用,暂时不涉及数据库的配置。 使用IDEA创建
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 分钟
深入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 分钟
讨论
共 0 条加载评论中…