Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.setht.fxtests;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.Background;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- public class TransparentExample extends Application{
- public static void main(String[] args) {
- launch(args);
- }
- public void start(Stage primaryStage) throws Exception {
- StackPane layout = new StackPane();
- Scene root = new Scene(layout, 480, 360);
- //BEGIN TRANSPARENT CODE
- //make the stage (window) transparent with no decorations
- // alternatives include DECORATED, UNDECORATED, and UTILITY (and UNIFIED)
- // http://aquafx-project.com/documentation.html see <h3>Styling stage</h3>
- // http://docs.oracle.com/javase/8/javafx/api/index.html?javafx/stage/StageStyle.html
- primaryStage.initStyle(StageStyle.TRANSPARENT);
- //set the scene's (container) fill to transparent
- // it's looking for a Paint object but it seems to accept a Color object instead
- root.setFill(Color.TRANSPARENT);
- //finally, apparently the layout itself has a background we need to change
- // remember that the layout is a child of the scene,
- // unlike Swing where the layout manager contains the panel
- // it seems you can do this with a css style method, but I'm not familiar with this yet
- //layout.setStyle("-fx-background-color: transparent;");
- // so I'm using the setBackground() method instead
- layout.setBackground(Background.EMPTY);
- //you can't see the title anywhere, not even in the dock or taskbar
- // so there's no real point in setting it
- primaryStage.setTitle("Transparent Window");
- primaryStage.setScene(root);
- primaryStage.show();
- Button button = new Button("I'm floating!");
- layout.getChildren().add(button);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement