Last active
December 4, 2018 13:10
-
-
Save sXakil/bf645f2e2683ba8f71f4255553c7735b to your computer and use it in GitHub Desktop.
JavaFX Splash-screen controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.ums.pau.resources; | |
| import com.ums.pau.SceneSwitcher; | |
| import javafx.application.Platform; | |
| import javafx.fxml.Initializable; | |
| import javafx.scene.control.Label; | |
| import java.io.IOException; | |
| import java.net.URL; | |
| import java.util.ResourceBundle; | |
| public class SplashController implements Initializable { | |
| public Label loader; | |
| @Override | |
| public void initialize(URL location, ResourceBundle resources) { | |
| new SplashScreen().start(); | |
| } | |
| class SplashScreen extends Thread { | |
| public void run() { | |
| try { | |
| for(int i = 1; i <= 100; i++) { | |
| final int loaded = i; | |
| Thread.sleep(25); | |
| Platform.runLater(() -> loader.setText(loaded + "%")); | |
| } | |
| Thread.sleep(1000); | |
| Platform.runLater(() -> { | |
| try { new SceneSwitcher().switchSceneTo("resources/LandingControls/landing.fxml"); } | |
| catch (IOException e) { e.printStackTrace(); } | |
| }); | |
| } catch (InterruptedException e) { e.printStackTrace(); } | |
| } | |
| } | |
| } | |
| /* | |
| Use the following two lines in your Main controller for splash screen with transparent background: | |
| newScene.setFill(Color.TRANSPARENT); | |
| primaryStage.initStyle(StageStyle.TRANSPARENT); | |
| Project where I've used this: | |
| https://github.com/sXakil/UMS | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment