Contents
JavaFX
Desktop applications in Java: windows, controls, FXML, CSS, properties and bindings.
1.Getting started
- What JavaFX isWhy JavaFX exists, where it is used, which version this course targets and what app we will build.
- Creating a projectCreate a JavaFX project from the Maven archetype, update pom.xml, understand module-info.java and open the window with mvn javafx:run.
- Application, Stage and SceneThe JavaFX application lifecycle: init, start and stop, the Stage window, the Scene and the JavaFX Application Thread.
2.Building the interface
- VBox and HBoxThe VBox and HBox containers: a column and a row of nodes, padding, alignment and stretching a field to the full width.
- BorderPane and GridPaneA window frame with BorderPane: top, bottom, left panel and center. A form laid out as a grid with GridPane and column settings.
- ControlsLabel, TextField, TextArea, ComboBox, CheckBox and Button: how to create a control, set a starting value and read what the user entered.
- Events and handlersHow JavaFX reports user actions: setOnAction, method references, the Enter key in a field, mouse clicks and keyboard shortcuts.
- Properties and bindingsJavaFX properties: change listeners, bind, computed values, your own IntegerProperty and disabling a button without a single if.
3.Lists and tables
4.FXML and styles
- FXML: the window markupDescribe the interface in an FXML file instead of Java code: adding javafx-fxml, the resources folder, FXMLLoader, attributes, nested elements and fx:id.
- The FXML controllerA controller class for FXML: the fx:controller attribute, fields annotated with @FXML, the initialize method and onAction handlers.
- Scene BuilderThe visual FXML editor: where to get Scene Builder, which panels it has, how to set the controller, fx:id and handlers, and what it changes in the file.
- CSS stylesStyling JavaFX with CSS: a stylesheet in the resources, attaching it to the scene, selectors by class and fx:id, pseudo-classes and properties with the -fx- prefix.
5.Finishing the app
- Dialogs and AlertStandard JavaFX dialogs: an Alert warning, a delete confirmation with custom buttons, text input with TextInputDialog and tying a dialog to its window with initOwner.
- Multiple windowsA second window for editing a note: its own FXML and controller, a new Stage, modality, passing data between windows and switching scenes.
- Saving notes to JSONNotes survive a restart: the Jackson 3 library, a NoteStorage class that reads and writes notes.json and automatic saving through a list listener.
- Background tasks: Task and Platform.runLaterWhy long work in the JavaFX thread freezes the window, how to hand a result back to the interface with Platform.runLater and how to do the same with a Task and a loading indicator.
- Packaging: jlink and jpackageHow to give the application to a user without Java installed: a runtime image with mvn javafx:jlink and a ready program or installer with jpackage.
6.Graphics and animation
- Animation: transitions and TimelineFading the table in with FadeTransition, a status message that fades away, shaking a field with TranslateTransition and a pulsing counter built with Timeline and KeyFrame.
- Charts: PieChart, BarChart and LineChartA statistics window for the notebook: a pie chart by category, a bar chart with two series, the CategoryAxis and NumberAxis axes, and filling them from the list of notes.
- Drawing on a CanvasCanvas and GraphicsContext: rectangles, circles, lines and text, fill and stroke colors, drawing with the mouse and redrawing from stored data in a Sketch window.