Creating a Basic JavaFX Application
Learn how to create your first JavaFX application by extending the Application class, setting up the primary stage, and launching your app.
A Beginner's Guide to JavaFX Development
This documentation is designed for students who have a basic understanding of Java and want to learn JavaFX. We'll use the Jukebox project as a reference implementation to explain key JavaFX concepts through practical, hands-on examples.
The Jukebox is a music library management application that allows users to browse, play, and manage their music collection. It demonstrates a complete JavaFX application with multiple views, data persistence, and a clean MVC (Model-View-Controller) architecture.
This tutorial covers:
Browse our collection of how-to guides that walk you through specific JavaFX tasks using real code from the Jukebox project:
Learn how to create your first JavaFX application by extending the Application class, setting up the primary stage, and launching your app.
Discover how to define your UI declaratively using FXML files and load them with FXMLLoader.
Learn how controllers handle user interactions, receive FXML-injected elements, and manage view lifecycle with the initialize() method.
Understand the single-window architecture and how to switch between different views using a container-based approach.
Create simple model classes to represent your application data, including enums and composition relationships.
Master ListView configuration, ObservableList usage, selection handling, and working with collections.
Implement add functionality for your ListView, including creating new objects, adding to collections, and auto-selecting new items.
Learn how to safely remove items from ListView with confirmation dialogs, including proper cleanup of selection state.
Implement two-way editing of list items using selection listeners, TextField listeners, and automatic ListView refresh.
Display tabular data with TableView, configure columns with cell value factories, and handle row selection.
Serialize and deserialize your application data to JSON files using the Gson library for easy persistence.
Populate a ComboBox from enum values, set default selections, and respond to user selections with change listeners.
Create resizable, divider-based layouts with SplitPane to organize complex UIs into separate, adjustable sections.
Show confirmation dialogs and information alerts to users, and handle their responses in your application logic.
Apply CSS stylesheets to your JavaFX application to create a custom look and feel, just like styling web pages.
Understand how controllers can communicate with each other using static references and global state management.
Implement automatic saving of data when users navigate between views, preventing data loss from forgotten saves.