Kensoft PH
  • Download
  • Contact
  • About
Java Quiz
No Result
View All Result
Kensoft PH
  • Download
  • Contact
  • About
Java Quiz
No Result
View All Result
Kensoft PH
No Result
View All Result
Home Java

How to create JavaFX Splash Screen | 100% best for beginners

April 19, 2021 - Updated on September 21, 2022
in Java
Reading Time: 4 mins read
2
JavaFX Splash Screen
2.1k
VIEWS
Share on FacebookShare on TwitterShare via Email

Contents

  • JavaFX Splash Screen Tutorial
  • Source Code of JavaFX Splash Screen
      • FX_Splash.fxml – This is the JavaFX Splash Screen window
      • FX_SplashController.java – This is the controller of your Splash.fxml
      • Main.java – This is the main class
    • JavaFX controller explanation
  • YouTube Video

JavaFX Splash Screen Tutorial

Most application nowadays have a splash screen when you are opening the application and many beginners wanted to learn how to make it. JavaFX splash screen, we will make a very simple splash screen in JavaFX for you to know and learn how to make a splash screen in JavaFX. The first thing we need to do is to create a new project from your NetBeans IDE. I assumed that you already knew about setting up a JavaFX.

If you don’t know how to set up JavaFX in your NetBeans IDE, you can learn from here. Once you are done creating the project, then create the JavaFX Main Class and two (2) FXML files, the first one should be your JavaFX Splash Screen with Java Controller. The second one is your main window, your dashboard, or something. You have the freedom to design your FXML file using the Scene Builder. I am going to include my source code here for your reference. Kindly see the source code below.

Source Code of JavaFX Splash Screen

Note: This is just an example. If you copy my source code and paste it into your project. You may get a bunch of errors. It is just a reference.

FX_Splash.fxml – This is the JavaFX Splash Screen window

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>


<AnchorPane id="AnchorPane" fx:id="apane" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: linear-gradient(to left bottom, #021634, #2d1946, #581149, #7e003c, #981022);;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/16" fx:controller="kensoft.FX_SplashController">
<children>
<Label layoutX="132.0" layoutY="164.0" text="SPLASH SCREEN" textFill="WHITE">
<font>
<Font size="50.0" />
</font>
</Label>
</children>
</AnchorPane>

FX_SplashController.java – This is the controller of your Splash.fxml

package kensoft;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
* FXML Controller class
*
* @author KENSOFT
*/
public class FX_SplashController implements Initializable {

/**
* Initializes the controller class.
*/
@FXML
private AnchorPane apane;

private BorderPane borderPane;

@Override
public void initialize(URL url, ResourceBundle rb) {
splash();
}

private void splash() {
new Thread() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (Exception e) {
System.out.println(e);
}
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
borderPane = FXMLLoader.load(getClass().getResource("FX_Dashboard.fxml"));
Stage stage = new Stage();
Scene scene = new Scene(borderPane);
stage.setTitle("Kensoft PH");
stage.setScene(scene);
stage.setMinHeight(400);
stage.setMinWidth(600);
stage.show();
apane.getScene().getWindow().hide();
} catch (IOException ex) {
Logger.getLogger(FX_SplashController.class.getName()).log(Level.SEVERE, null, ex);
}

}
});
}
}.start();
}
}

Main.java – This is the main class

package kensoft;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
*
* @author KENSOFT
*/
public class Main extends Application {

@Override
public void start(Stage stage) throws IOException {
Parent pane = FXMLLoader.load(getClass().getResource("FX_Splash.fxml"));
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}

}

JavaFX controller explanation

When you notice the splash() method, the logic is in there. Let’s assume that our Splash window will last for at least 3 seconds. We created a new Thread() method and override it with the run() method and we set the Thread to 3000 milliseconds for 3 seconds. The Platform.runLater() is also a requirement if we will not implement the runLater() method, we will get an error while running it. Inside the try-catch exception, that is how to show the other window and to hide the JavaFX Splash screen. Just call the object apane which is the AnchorPane layout of the FX_Splash.fxml. apane.getScene().getWindow().hide(); .

JavaFX Splash Screen
 

YouTube Video

JavaFX Tutorial: Splash Screen in JavaFX using NetBeans IDE
Watch this video on YouTube.

Previous Post

How to set up JavaFX and Scene Builder in NetBeans IDE | 100% best for beginners

Next Post

How to create JavaFX Login application with CSS | 100% best for beginners

KENSOFT

KENSOFT

What’s up! Kent is my name. The name KENSOFT is derived from the words Kent and Software. My programming language of choice is Java

Related tutorials

How to use the JavaFX ToolBar
Java

How to use the JavaFX ToolBar | 100% Perfect Tutorial

January 24, 2023
13
JavaFX Context Menu
Java

How to use the JavaFX ContextMenu | 100% Perfect Tutorial

January 22, 2023
10
JavaFX MenuBar
Java

How to use the Menu Bar in JavaFX | 100% Perfect Tutorial

December 3, 2022 - Updated on January 23, 2023
76
Next Post
JavaFX login application

How to create JavaFX Login application with CSS | 100% best for beginners

Setting up JavaFX 16 with JDK 1.8

How to set up JavaFX 16 with JDK 1.8 in NetBeans IDE | 100% best for beginners

JavaFX Alert Dialogs | 100% best for beginners

JavaFX Alert Dialogs | 100% best for beginners

Comments 2

  1. Avatar of Wei Wei says:
    9 months ago

    Thank you for sharing this. Really helpful!

    0
    0
    Reply
    • Avatar of KENSOFT KENSOFT says:
      9 months ago

      You’re welcome, I’m glad you found it helpful.

      0
      0
      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Maximum upload file size: 20 MB. You can upload: image, audio, video, document, text. Drop files here

  • Trending
  • Comments
  • Latest
Failed to automatically set up a JavaFX Platform

Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

April 11, 2021 - Updated on July 3, 2022
MySQL database using XAMPP

How to connect Java to MySQL database using Xampp server | 100% best for beginners

October 27, 2020 - Updated on January 23, 2023
JavaFX 17

How To install JDK 17 and JavaFX 17 on NetBeans IDE | Best

November 15, 2021 - Updated on December 13, 2021
change the stage icon in JavaFX

How to change the stage icon in JavaFX | 100% best for beginners

May 23, 2021 - Updated on September 24, 2022
Failed to automatically set up a JavaFX Platform

Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

send SMS in java

How to send SMS in Java | 100% best example

3DES in Java and AES in Java

How to use AES and 3DES in Java | 100% best for beginners

JavaFX Splash Screen

How to create JavaFX Splash Screen | 100% best for beginners

How to use the JavaFX ToolBar

How to use the JavaFX ToolBar | 100% Perfect Tutorial

January 24, 2023
JavaFX Context Menu

How to use the JavaFX ContextMenu | 100% Perfect Tutorial

January 22, 2023
JavaFX MenuBar

How to use the Menu Bar in JavaFX | 100% Perfect Tutorial

December 3, 2022 - Updated on January 23, 2023
How to use the Slider in JavaFX | 100% Perfect Tutorial

How to use the Slider in JavaFX | 100% Perfect Tutorial

November 27, 2022

Latest Tutorials

How to use the JavaFX ToolBar

How to use the JavaFX ToolBar | 100% Perfect Tutorial

January 24, 2023
JavaFX Context Menu

How to use the JavaFX ContextMenu | 100% Perfect Tutorial

January 22, 2023
JavaFX MenuBar

How to use the Menu Bar in JavaFX | 100% Perfect Tutorial

December 3, 2022 - Updated on January 23, 2023

Popular Tutorials

  • Failed to automatically set up a JavaFX Platform

    Failed to automatically set up a JavaFX Platform SOLVED Apache NetBeans 12.3 | Best way

    0 shares
    Share 0 Tweet 0
  • How to connect Java to MySQL database using Xampp server | 100% best for beginners

    0 shares
    Share 0 Tweet 0
  • How To install JDK 17 and JavaFX 17 on NetBeans IDE | Best

    0 shares
    Share 0 Tweet 0
Facebook Instagram Youtube Github LinkedIn Discord
Kensoft PH

What’s up! Kent is my name. The name KENSOFT is derived from the words Kent and Software. My programming language of choice is Java, which I use to create computer applications. In a company, I created applications and a website.

Website

Privacy Policy

Terms and Condition

Sitemap

Services

Guest Post

Fiverr

Freelancer

Upwork

Categories

Website Status

Check the status

Latest Tutorials

How to use the JavaFX ToolBar

How to use the JavaFX ToolBar | 100% Perfect Tutorial

January 24, 2023
JavaFX Context Menu

How to use the JavaFX ContextMenu | 100% Perfect Tutorial

January 22, 2023
JavaFX MenuBar

How to use the Menu Bar in JavaFX | 100% Perfect Tutorial

December 3, 2022 - Updated on January 23, 2023

© 2023 Made With Love By KENSOFT PH

No Result
View All Result
  • Download
  • Java Quiz
  • Contact
  • About

© 2023 Made With Love By KENSOFT PH

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.