Prev Next

Java / JavaFX


What is JavaFX?


It can be considered as an alternative to Java Swing.

Is Java Applet deprecated?

Yes. As part of JDK 1.9 it is deprecated.

What is a Stage in JavaFX?

A javafx.stage.Stage in JavaFX is a top-level container that hosts a Scene, which consists of visual elements. The platform creates the primary stage and pass it to the start(Stage s) method of the Application class.

Explain the basic structure of a JavaFX application.

The main class for a JavaFX application extends the javafx.application.Application class.

The start() method is the main entry point for all JavaFX applications. So your main class will override it.



The main() method is not required for JavaFX application, however useful to launch in IDE without JavaFX launcher.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {
	public static void main(String[] args) {

	public void start(Stage primaryStage) throws Exception {
		primaryStage.setTitle("Welcome to");

		Button b = new Button("Click");

		StackPane layout = new StackPane();

		Scene scene = new Scene(layout, 300, 300);



Different inbuilt layout panes.
  • BorderPane,
  • HBox,
  • VBox,
  • StackPane,
  • GridPane,
  • FlowPane,
  • TilePane,
  • and AnchorPane.
Explain the JavaFX API.

javafx.stage holds the top level container classes for JavaFX application.

javafx.scene provides classes and interfaces to support the scene graph. In addition, it also provides sub-packages such as canvas, chart, control, effect, image, input, layout, media, paint, shape, text, transform, web, etc. There are several components that support this rich API of JavaFX.

javafx.animation has classes to add transition based animations such as fill, fade, rotate, scale and translation, to the JavaFX nodes.

javafx.application contains a set of classes responsible for the JavaFX application life cycle.

javafx.css contains classes to add CSSlike styling to JavaFX GUI applications.

javafx.event contains classes and interfaces to deliver and handle JavaFX events.

javafx.geometry contains classes to define 2D objects and perform operations on them.


Comments & Discussions