The program below is an example of what I'm actually trying to achieve.
I'm trying to do is recreate the picture above in JavaFX. However I am having difficulties because when I set the content of my stage to transparent it doesn't actually go transparent it still remains white.
@Override
public void start(Stage stage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
root.setStyle("-fx-background-color: rgba(0,0,0,0);");
scene.setFill(Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
The stage is visible from this code. I also set the content to transparent and changed the default style of the root pane to transparent.
I don't understand why this doesn't work, I'm setting the content to transparent but the background is still not transparent.
The result from the code I posted shows this, as you can see it's not transparent.
This question is almost a duplicate of:
- how to make transparent scene and stage in javafx?
The difference being that it is also asking to retain native window decorations, which is not possible with StageStyle.TRANSPARENT.
If you look closely at the sample windows provided in the question, the decoration areas differ slightly (e.g. one includes a stage icon in the upper left and the other does not). My guess is that the transparent window pictured in the question isn't actually using the OS window decorations at all, but is instead rendering its own decorations which look much like the OS window decorations (that is just a guess though).
Anyway, to achieve a similar effect with JavaFX, it is necessary that JavaFX be used to render the window decorations rather than the OS window manager. To do that, refer to the following question:
- JavaFX entirely customized windows?
In particular take a look at the Undecorator library:
- https://github.com/in-sideFX/UndecoratorBis
You will never be able to get the window decorations to exactly match the OS Window manager decorations, but you can create something that looks different and provides similar functionality. If you work at it, you might be able to achieve something that matches the OS window decorations pretty closely, similar to the window screenshot in your question. Though, if it were me, I would just go for a different look which was still clean and easily comprehensible by the user, similar to the default look provided by Undecorator.
Do you think this could be pulled off by creating an ImageView and using some sort of stage listener so when the stage is moved the imageview displays a new image of what's behind the application? Or is that overly complicating it?
The background capture to imageView approach is a reasonable alternate approach.
If you do want to use the imageView capture approach, you can use some of the ideas from the following answer:
- JavaFX effect on background
Note that the imageView capture type answer linked above won't completely accomplish what you wish and you still need to do some additional custom work to get exactly the effect you need as you move the stage around or as the desktop or windows under your window change. Possibly you may need to resort to logic outside of JavaFX to fully realize your goal, and discussion of how to do that is outside the scope of what I would be prepared (or able) to discuss here.
It's complicated no matter what you do, I don't really have a recommendation between the undecorator or the imageView capture approach.
Maybe if you mix JavaFX and Swing/AWT you may be able to do this by using a JFXPanel and the AWT PERPIXEL_TRANSPARENT
feature. I haven't tried this combo, but per pixel settings for AWT are demonstrated in this oracle sample as discussed in How to Implement Per-Pixel Translucency.