JavaFX Main App wird nicht geöffnet

zhermann

Mitglied
Hallo,

versuche gerade einen Splashscreen in meine App zu integrieren.

Main.java
Java:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.fxml.FXMLLoader;

public class Main extends Application {

	@Override
	public void start(Stage splashStage) throws Exception {
		Parent splash = FXMLLoader.load(getClass().getResource("Splash.fxml"));
		Scene scene = new Scene(splash);
		splashStage.setScene(scene);
		splashStage.initStyle(StageStyle.UNDECORATED);
		splashStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}
SplashController.java
Java:
public class SplashController implements Initializable {

    @FXML
    private StackPane rootPane;

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        System.out.println(" Splash ini");
        new SplashScreen().run();
    }

    class SplashScreen extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(5000);
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        Parent root = null;
                        try {
                            root = FXMLLoader.load(getClass().getResource("Reporter.fxml"));
                        } catch(IOException ex) {
                            ex.printStackTrace();
                        }
                        Scene masterscene = new Scene(root, 800, 600);
                        Stage masterStage = new Stage();
                        masterStage.setScene(masterscene);
                        masterStage.setTitle("SAP Reporter v0.1 ");
                        masterStage.show();
                        rootPane.getScene().getWindow().hide();
                    }
                });
            } catch(InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

Warum auch immer, wird das initialize im SplashController nicht ausgeführt. Aber warum?
Das Splashscreen wird korrekt angezeigt und dat wars. Sieht einer den Fehler.
 
Zuletzt bearbeitet von einem Moderator:
Schlechte Idee, auf diese Art: Dafür sind eher Preloader gedacht.
Aber ich denke auch, dass du nur den Controller nicht im FXML-Dokument verlinkt hast.
 
Splash.fxml

XML:
<?xml version="1.0" encoding="UTF-8"?><?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane maxHeight="175.0" maxWidth="400.0" minHeight="175.0" minWidth="400.0" style="-fx-background-color: #4E4E4E;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SplashController">
   <children>
      <ImageView fitHeight="96.0" fitWidth="424.0" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
         <image>
            <Image url="@../../resources/32x32/BAG_3c.jpg" />
         </image>
      </ImageView>
      <Label fx:id="lblSplash" layoutX="14.0" layoutY="125.0" text="Label" textFill="WHITE" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="118.0" />
      <ProgressBar fx:id="proSplash" layoutX="14.0" layoutY="142.0" prefWidth="200.0" progress="0.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" />
   </children>
</AnchorPane>
Reporter.fxml

XML:
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="600.0" minWidth="800.0" style="-fx-background-color: #4A5459;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ReporterController">
   <children>
      <MenuBar layoutX="173.0" layoutY="21.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <menus>
          <Menu mnemonicParsing="false" text="Datei">
            <items>
                  <MenuItem fx:id="mnuOpenImport" mnemonicParsing="false" onAction="#mnuOpenImport" text="Öffne Import">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/document-import-2.png" />
                           </image>
                        </ImageView>
                     </graphic>
                  </MenuItem>
                <MenuItem fx:id="mnuOpenReport" mnemonicParsing="false" onAction="#mnuOpenReport" text="Öffne Report">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/office-chart-area.png" />
                           </image>
                        </ImageView>
                     </graphic>
                  </MenuItem>
                  <SeparatorMenuItem mnemonicParsing="false" />
                  <MenuItem fx:id="mnuSaveReport" mnemonicParsing="false" onAction="#mnuSaveReport" text="Speichern">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/document-export.png" />
                           </image>
                        </ImageView>
                     </graphic>
                  </MenuItem>
                <MenuItem fx:id="mnuSavAsReport" mnemonicParsing="false" onAction="#mnuSavAsReport" text="Speichern als ...">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/document-save-all.png" />
                           </image>
                        </ImageView>
                     </graphic>
                  </MenuItem>
                  <SeparatorMenuItem mnemonicParsing="false" />
                  <MenuItem fx:id="mnuOption" mnemonicParsing="false" onAction="#mnuOption" text="Einstellungen">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/configure-5.png" />
                           </image>
                        </ImageView>
                     </graphic>
                  </MenuItem>
                  <SeparatorMenuItem mnemonicParsing="false" />
              <MenuItem fx:id="mnuExit" mnemonicParsing="false" onAction="#mnuExit" text="Beenden">
                     <graphic>
                        <ImageView>
                           <image>
                              <Image url="@../../resources/16x16/application-exit-4.png" />
                           </image>
                        </ImageView>
                     </graphic></MenuItem>
            </items>
          </Menu>
          <Menu mnemonicParsing="false" text="?">
            <items>
              <MenuItem fx:id="mnuAbout" mnemonicParsing="false" onAction="#mnuAbout" text="Über..." />
            </items>
          </Menu>
        </menus>
      </MenuBar>
      <ToolBar layoutX="133.0" layoutY="62.0" prefHeight="40.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="26.0">
         <items>
            <ImageView>
               <image>
                  <Image url="@../../resources/32x32/document-open-5.png" />
               </image>
            </ImageView>
            <ImageView>
               <image>
                  <Image url="@../../resources/32x32/document-import-2.png" />
               </image>
            </ImageView>
            <ImageView>
               <image>
                  <Image url="@../../resources/32x32/document-export.png" />
               </image>
            </ImageView>
            <ImageView>
               <image>
                  <Image url="@../../resources/32x32/document-save-all.png" />
               </image>
            </ImageView>
         </items>
      </ToolBar>
      <AnchorPane layoutX="130.0" layoutY="466.0" maxHeight="25.0" maxWidth="-Infinity" minHeight="25.0" minWidth="-Infinity" prefHeight="25.0" prefWidth="400.0" style="-fx-background-color: #F6F6F6;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
         <children>
            <Label fx:id="stbLabel" layoutX="28.0" layoutY="4.0" prefHeight="17.0" prefWidth="292.0" text="Label" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="4.0" AnchorPane.rightAnchor="105.0" AnchorPane.topAnchor="4.0">
               <opaqueInsets>
                  <Insets />
               </opaqueInsets></Label>
            <ProgressBar fx:id="stbProgress" layoutX="200.0" layoutY="4.0" prefHeight="18.0" prefWidth="96.0" progress="0.0" AnchorPane.bottomAnchor="3.0" AnchorPane.rightAnchor="4.0" AnchorPane.topAnchor="4.0" />
         </children>
      </AnchorPane>
   </children>
</AnchorPane>
 
Zuletzt bearbeitet von einem Moderator:
Mit dem Preloader komme ich im Moment noch nicht klar, bin Java Azubi 😉
Wollte nur dem User Anzeigen, das das Program startet, aber im Hintergrund noch die DB usw. geladen wird.

Hab mir das ganze nochmal angesehen. Ohne Veränderungen, allerding anderes Laptop, staret das Program, aber der Splashscreen bleibt auch offen. 😱

Sollte der nicht mit:
Java:
rootPane.getScene().getWindow().hide();
geschlossen werden?
 

Zurück
Oben