1

There appears to be a delay in applying my dark UI CSS to a stage when it first appears. This causes an ugly looking white flash. How can I prevent this? Code and demo gif below.

    if (presetDialog == null) {
        // Create the preset dialog
        presetDialog = new Stage();
        presetDialog.initOwner(stage);
        presetDialog.setTitle("Edit Preset");

        // Load fxml
        FXMLLoader loader = new FXMLLoader(getClass().getResource("EditPreset.fxml"));
        try {
            loader.setController(this);
            BorderPane pane = loader.load();
            Scene scene = new Scene(pane);
            scene.getStylesheets().addAll(stage.getScene().getStylesheets());
            presetDialog.setScene(scene);
        } catch (IOException e) {
            e.printStackTrace();
        }           
    }

    presetDialog.showAndWait();

Ugly white flash before CSS is processed

4
  • So aesthetically unpleasing. You could try reporting a defect with Oracle, or put the style change in a new thread. Oct 13, 2018 at 15:34
  • I also don't understand why it is not picking up the style automatically from it's owner. With an alert dialog just setting the owner is enough. Here I added a line to copy the CSS from owner scene to my new scene because it wasn't applying (inheriting) the CSS at all.
    – John Baker
    Oct 13, 2018 at 15:46
  • This isn't a CSS issue at all. Any time you set or change scenes on a single stage in JavaFX, there's a moment where you see the white background of the stage before the new scene is loaded. See stackoverflow.com/a/25467189/8729420
    – faris
    Oct 13, 2018 at 18:34
  • Thanks for the info and workaround. I've mocked up a psuedo dialog decoration which works but it looks a bit weird and obviously not very platform friendly to do it that way. Why is there no stage with transparent content area but not transparent decoration? Why would you assume windows are white inside?
    – John Baker
    Oct 13, 2018 at 22:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.