Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8094073

[Preloader] with StageStyle.TRANSPARENT is shown only when Main app starts

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8u11
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7

      Description

      Hi,

      I've made a simple preloader for my app. Nothing special: an image (a semitransparent .png) and a ProgressBar.


      This is the FXML:

          <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="804.0" minWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="it.app.preloader.SplashScreenUi">
            <!-- TODO Add Nodes -->
            <children>
                <ImageView fitHeight="804.0" fitWidth="800.0" pickOnBounds="true" preserveRatio="true" smooth="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                   <image>
                      <Image url="@splash.png" />
                   </image>
                </ImageView>
              <ProgressBar fx:id="progressBar" prefWidth="200.0" progress="-1.0" AnchorPane.bottomAnchor="15.0" AnchorPane.leftAnchor="15.0" AnchorPane.rightAnchor="15.0" />
            </children>
          </AnchorPane>

      and this is the code:

          public void start(Stage stage) throws Exception {
                  log.debug("--->SPLASH SCREEN<-----");
                  this.stage = stage;
                  if (stage != null) {
                      stage.initStyle(StageStyle.TRANSPARENT);
                      stage.setScene(createPreloaderScene());
                      stage.show();
                  }
              }
            
          private Scene createPreloaderScene() {
                  try {
                      AnchorPane root = FXMLLoader.load(SplashScreenUi.class.getResource("SplashScreenUi.fxml"));
                      for (Node node : root.getChildren()) {
                          if (node instanceof ProgressBar) {
                              progressBar = (ProgressBar) node;
                              progressBar.setProgress(-1);
                          }
                      }
            
                      Scene scene = new Scene(root);
                      scene.setFill(Color.TRANSPARENT);
            
                      return scene;
                  } catch (Throwable e) {
                      e.printStackTrace();
                  }
                  return null;
              }

      With stage.initStyle(StageStyle.TRANSPARENT); I see that the preloader is opened (I see the icon in the taskbar) but I see nothing else (nor image, not progress bar, no stage).
      It is opened ONLY when the Main application is shown.

      Instead if I use stage.initStyle(StageStyle.UNDECORATED); all works as expected and the splash screen is shown BEFORE the Main application is displayed.

        Attachments

          Activity

            People

            Assignee:
            kcr Kevin Rushforth
            Reporter:
            danielejfx Daniele (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: