Home Snippets Projects Donate

Get Snippets For:

   Java    HTML/CSS JavaScript

JavaFX Starter Template

Code Description:

The most basic and bare-bones JavaFX template needed to start any Java application with a UI. This includes all necessary components to set up a Scene and configure the window with a title.

Full JavaFX Starter Template Code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Demo extends Application {

    public static void main(String[] args) {

    public void start(Stage primaryStage) throws Exception {
	VBox root = new VBox();
	Label label = new Label("Hello World");
	primaryStage.setTitle("Window Title");
	primaryStage.setScene(new Scene(root, 700, 400));


How to Run This Code:

Make sure that your Class name is the same as ours. In this case, we are using the Class name of "Demo". Alternatively, you can change the Class name in the provided code to match yours.

Note: You will NOT be able to copy and paste this code into your IDE unless you first set up JavaFX for your project. Check out this link if you need help setting up JavaFX:

JavaFX Comprehensive Setup Guide


JavaFX Starter Template Output Image

Code Notes:

Related Links:

JavaFX Comprehensive Setup Guide JavaFX Labels JavaFX Buttons JavaFX VBox (Vertical Box Layouts) JavaFX HBox (Horizontal Box Layouts)