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?