2

I already searched on google and here for a few hours but didn't find any answer for this problem. I want to create an application, which will only contain icons. It doesn't have any purpose. It's just for me to practice JavaFX. But I can't figure out why there is a visible window even though I set it to transparent.

As you can see here, this is what I'm trying to do. This is, how it should look like just as I start the application (As I said, it's just a random Icon with no purpose.. still learning and this is my practice project). But for some reason, it will load a stage/scene for a few milliseconds which will create a "one-time-flickering" effect. This is how the window looks like. It's just the Stage/Scene how I set it up (it's that big just to see it clearer and it's half tranparent because it's too fast and I couldn't create a better screenshot :( ) but without the transparent setting. Here is the Code I have:

public class MainNotification extends Application {

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
    primaryStage = new Stage(StageStyle.TRANSPARENT);
    GridPane pane = new GridPane();
    Scene scene = new Scene(pane);
    scene.setFill(Color.TRANSPARENT);
    primaryStage.setScene(scene);
    TestPloppingWindow.build(primaryStage);
    primaryStage.show();
}

}

And:

public class TestPloppingWindow {

private static boolean isBuild;
private static double posX = 100;
private static double posY = 100;

public static Stage build(Stage stage) {
    if (!isBuild()) {
        GridPane pane = (GridPane) stage.getScene().getRoot();
        ImageView image = new ImageView(
                new Image(MainNotification.class.getResourceAsStream("/Ressource/icon.png"), 100, 100,
                        true, true));
        image.setOnMouseClicked(e -> {
            biggerIcons();
        });
        pane.getChildren().add(image);
        pane.setAlignment(Pos.CENTER);
        stage.setScene(stage.getScene());
        pane.setPrefSize(500, 250);
        setBuild(true);
    }
    return stage;
}

public static void biggerIcons() {
    Stage stage = new Stage(StageStyle.TRANSPARENT);
    stage.setX(posX = posX + 100);
    stage.setY(posY = posY + 100);
    GridPane pane = new GridPane();
    Scene scene = new Scene(pane, Color.TRANSPARENT);
    stage.setScene(scene);
    ImageView view = new ImageView(
            new Image(TestPloppingWindow.class.getResourceAsStream("/Ressource/icon.png")));
    pane.getChildren().add(view);
    stage.show();
}

public static boolean isBuild() {
    return isBuild;
}

private static void setBuild(boolean isBuild) {
    TestPloppingWindow.isBuild = isBuild;
}

}

Whenever I click on the little Icon, a bigger one will show up (biggerIcons()) and there, I don't have that problem. It fades in smoothly without any stage/scene blink problems. Does anyone know how to fix that?

Ulli
  • 21
  • 1
  • 2

1 Answers1

0

Hello sir this code stage.setScene(stage.getScene());, i am finding it hard to understand, also this code

if (!isBuild()) {

   ....

  setBuild(true);
}
return stage;

This logic here to me is not very (I do not understand). No need to return Stage

it will load a stage/scene for a few milliseconds which will create a "one-time-flickering" effect

its because of this stage.setScene(stage.getScene()); remove it, its not useful in your code, it simply unsets the Stage's Scene and re-sets it

Hope it helps

Elltz
  • 10,730
  • 4
  • 31
  • 59
  • Tried it.. but unfortunately it doesn't work.. Even the easiest Code without any methods to show a simple Icon won't show up without that blinking effect.. somebody on twitter said it's a bug with some linux distributions.. after trying that on my home PC I figured he was right...on Windows and Mac, this doesn't happen. So it's a Bug on some Linux Distributions. (I used OpenSuse, he used Arch Linux... both x64.. both had the bug) – Ulli Oct 24 '15 at 20:13