Introduction to JavaFX Applications
JavaFX is a software platform to design, create, test, and deploy different platforms Graphical User Interface applications, Rich Internet Applications, and Desktop Applications. JavaFX, developed in Java, serves as the standard GUI library intended to replace Swing. It provides support for web browsers and desktop personal computers running on Linux, MS Windows, and macOS. Additionally, JavaFX extends its support to various versions of MS Windows, including Windows Vista, Windows 7, Windows 8, and Windows 10 operating systems. Several aspects, such as working, creation, and examples of JavaFX, will be discussed in the following sections.
Structure of JavaFx Application
Let us discuss the structure of the JavaFX application.
Stage
The stage is a window that consists of all the JavaFX application objects. The Stage class of the javafx.stage package in Java denotes it.
Width and Height are the two parameters of the stage that determine the position. It is divided into a Title bar and borders. i.e., Content Area and Decorations.
There are five types of stages available.
- Decorated
- Unified
- Utility
- Transparent
- Undecorated
Scene
In JavaFX, Scene denotes the physical contents of an application. It also consists of several contents of a scene graph. It is denoted by the Scene class of the java package javafx.scene.
Scene Graph and Nodes
The scene’s contents will be in a tree-like or hierarchical data structure. It is known as the Scene Graph. In contrast, a scene graph’s graphical or visual object is known as the Node.
A Node consists of :
- User Interface controls such as Text Area, Checkbox, Button, Choice Box, etc.
- 2D and 3D Geometrical (Graphical) objects such as polygons, circles, Rectangles, etc.
- Several Media elements, such as Image, video, and audio objects.
- Layout Panes or Containers such as Flow Pane, Border Pane, Grid Pane, etc.
The Node class is the superclass of all available nodes in the package javafx.scene denotes a node in JavaFX.
A Node is of 3 types –
- Root Node
- Branch Node
- Leaf Node
1. Root Node: The root node is the first Scene Graph.
2. Branch Node or Parent Node: The branch node, also known as the parent node, is the node with child nodes. The parent class is the abstract class of the package javafx.scene, the base class of the parent nodes present.
Parent Nodes can be of the following types:
- Group
- Region
- WebView
Group: All the children nodes are available as a list in this collective node, i.e., the group node. Child nodes are rendered in the same order as the group node’s rendering. Any transformation or effect state applied to the group will be applied to all the child nodes.
Region: Base class of every JavaFX Node-based User Interfaces Control such as Chart, Control, and Pane.
WebView: This node manages a web engine and helps display all the contents.
3. Leaf Node: A node without child nodes is called a leaf node. E.g., Box, Rectangle, ImageView, Ellipse, and MediaView are leaf nodes.
Features of JavaFx
Some of the features are as follows.
- To create shapes like cylinders, boxes, and spheres, 3D graphics features are available.
- The application’s UI (User Interface) can be created using XML-based language, FXML.
- Using CSS (Cascading Style Sheets), User Interface components in JavaFX can be styled.
- The humongous number of in-built user interfaces controls, such as DatePicker, TableView, WebView, Form Controls, and ListView, are also available in JavaFX.
- A Scene Builder tool is available in JavaFX to design user interfaces (UI) that do not need to write code. This tool can be integrated into almost all the important IDEs, such as Eclipse, Netbeans and
- Almost all operating systems can create native installable packages for JavaFX applications. This will create a similar experience in launching as in any native application.
Implementation of JavaFX Application
Now, let us see a sample program for demonstrating the JavaFX Application.
Example: Java program to demonstrate JavaFX Application
import javafx.event.EventHandler;
import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
//create a class that extends Application class
public class JFXApplicationExample extends Application {
//main method
public static void main(String[] args) {
//method to launch the JavaFX application
launch(args);
}
@Override
//strat the application
public void start(Stage primaryStage) {
//set a title to the stage
primaryStage.setTitle("JavaFX Application Example!");
Button b = new Button();
b.setText("Click Me");
b.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event) {
System.out.println(" Hoorayyy... I am working !!!!");
}
});
StackPane r = new StackPane();
r.getChildren().add(b);
//set a scene to the stage by setting height and width of the stage
primaryStage.setScene(new Scene(r, 300, 250));
//display the stage
primaryStage.show();
}
}
Sample Output:
A dialog box appears on clicking the run button after successfully compiling the code, as shown below.
It can be seen that the dialog box has the title “JavaFX Application Example” and a button with the text “Click Me”. When the button is clicked, the output will be displayed in the Eclipse console, as shown below.
A successful display of the output shows that the application is working fine.
Real-world Applications of JavaFX
Application | Area of Use |
NEOS – New Eurovision Operations System | Television |
Template Editor IAV | Vehicle fleet data analysis |
Network Capacity Optimization Emirates Airline | Aviation |
Trading App | Trading |
AIDA German AIDS Foundation | Office |
QuoteMonitor | Finance |
MuseoID | Office |
James Webb Space Telescope (JWST) Flight Dynamics Ground System (FDGS) Nasa | Space |
Atlas Trader | Finance |
MINT TRMS | Training |
PSI Advanced Scheduling and Monitoring / ASM | Manufacturing Execution Systems
|
GEONS Ground System Software (GGSS) Nasa | Space |
Navigator Lynden | Dispatching |
AMMOS Asteroid Explorer Nasa | Space |
Deep Space Trajectory Explorer Nasa | Space |
eteoBoard Saxonia Systems AG | Scrum board |
FORUM Carl Zeiss Meditec AG | Medical |
Center Device | Cloud Service |
CuratorOR Caliop | Hospitals / Surgery |
Conclusion – JavaFX Applications
JavaFX is a platform that helps in the development process, such as designing, creating, and testing GUI applications. Developers have developed JavaFX to replace Swing in Java. This document details a JavaFX application’s features, structure, implementation, and real-world examples.
Recommended Articles
We hope that this EDUCBA information on “JavaFX Applications” was beneficial to you. You can view EDUCBA’s recommended articles for more information.