Tech Flow
04.04.2025

JavaFX: the (unexpected) Front End for those who love the Back End

Learn how to build desktop GUIs using JavaFX, the Java library made for front-end development. This article covers the basics, walks you through a mini “emotion app,” and introduces tools like Scene Builder to speed things up. Perfect for back-end developers ready to explore the visual side of Java.

Written by:
Andrea Italiano

Andrea Italiano

Backend Junior
Article cover image

SHARE

JavaFX: A Complete Guide to Front-End with Java

If you come from the back-end world, building UIs and working with layouts might feel like unfamiliar territory. But if you write Java and want to build simple, functional GUIs without leaving your ecosystem, JavaFX might be the surprise you didn't expect.

In this article, you'll discover:

✅ What JavaFX is and why it's worth your time
✅ Key concepts explained in plain English
✅ How to build a mini “emotion journey” app
✅ A visual tool to make layout easy
🎁 A bonus resource for deeper learning

Wait, Java can do Front-End?

Yes—and it does it locally.

JavaFX lets you create desktop graphical apps (rich clients) that don’t rely on browsers, servers, or Postman.

It's not meant for the web, but it’s great for internal tools, local utilities, or interactive demos.

JavaFX in 5 Key Concepts

JavaFX is a graphics library for building GUI applications. Here’s what you need to know to get started:

  • Stage: the main application window
  • Scene: everything that lives inside the Stage
  • Scene Graph: a tree-like structure of nodes (buttons, layouts, text, etc.)
  • Node: any visual element like a button or label
  • Events: handlers that respond to user actions (clicks, input…)

JavaFX apps follow a clear lifecycle: init()start()stop()
Everything kicks off with a simple call to launch().

Hierarchy Diagram

Your First JavaFX Project (with Emotions Included)

Let’s build a small app that displays emotions.
You’ll create 6 buttons—each one tied to an emotion. Click one, and a description appears.

Requirements
  • IDE: IntelliJ IDEA
  • JavaFX installed
  • Scene Builder (optional, but highly recommended)
Step-by-step:
  1. Create a new JavaFX project
  2. Create a class that extends Application
  3. Override the start(Stage stage)method
  4. Add 6 buttons (joy, anger, fear, sadness, surprise, disgust)
  5. Add a toolbar below the buttons with a label for the emotion description
  6. Add a heart-shaped ❤️ button to “start the journey”
Event Handling

For each button → setOnAction (event -> ...)
Use a Map<String, String> to store emotion descriptions and display them in the label when clicked.

Want the full code? Check out the project here

Handy Tools

🛠 Scene Builder
If you want to skip the manual layout struggle, use Scene Builder.
Drag and drop UI components, arrange them visually, and export FXML.

📦 FXML + Controller
Scene Builder helps separate UI and logic. The .fxml file defines the layout, while a Java controller handles events.

emotions javafx

Key Takeaways
  • JavaFX is an underrated way to build desktop UIs in Java
  • Great for prototypes, internal tools, educational or standalone apps
  • Scene Builder makes layout easier—perfect if you’re more dev than designer
  • With a few lines of code, you can build interactive, clean interfaces
Ready to dive deeper?

👉 JavaFX: Sample Projects & Exercises
🎓 Theories of Emotion by Paul Ekman

GET IN
TOUCH

Our mission is to turn your needs into solutions.

Contact us to collaborate on crafting the one that fits you best.