JavaFX: can you create a stage that doesn't show on the task bar and is undecorated?

前端 未结 6 819
予麋鹿
予麋鹿 2020-12-15 21:55

I\'m trying to create a stage that doesn\'t appear on the Windows task bar and is undecorated (no borders and no close/minimize/maximize buttons). My end goal is to create a

6条回答
  •  清歌不尽
    2020-12-15 22:33

    Inspired by @Loki solution with a little upgrade (in my opinion)

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    
    public class TransparentAndUtilityStageApp extends Application {
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
            primaryStage.initStyle(StageStyle.UTILITY);
            primaryStage.setOpacity(0.);
            primaryStage.show();
    
            Stage stage = new Stage();
            Label label = new Label("Rainmeter");
            StackPane stackPane = new StackPane(label);
            stackPane.setPrefSize(600, 400);
            stackPane.setStyle("-fx-background-color: transparent;");
    
            Scene scene = new Scene(stackPane);
            scene.setFill(null);
    
            stage.initOwner(primaryStage);
            stage.initStyle(StageStyle.TRANSPARENT);
            stage.setScene(scene);
            stage.show();
        }
    }
    

提交回复
热议问题