3 Replies Latest reply: Mar 20, 2013 4:12 AM by SlashWang RSS

    A javaFX Stage could be both StageStyle.UTILITY and StageStyle.TRANSPARENT

    SlashWang
      I mean that when using a stage with stageStyle.UTILITY, I don't want to show the "solid white background " but a transparent background.

      I need a stage doesn't shown on the windows' task bar below(stageStyle.UTILITY can satisfy), and I need a transparent background(StageStyle.TRANSPARENT can satisfy)so that I can define the close button style of my stage.


      But it seems strange that stageStyle.UTILITY or StageStyle.TRANSPARENT only fit one of my request.

      Thank you.
        • 1. Re: A javaFX Stage could be both StageStyle.UTILITY and StageStyle.TRANSPARENT
          shakir.gusaroff
          Hi. You can use a transparent stage with a custom close button:
          import javafx.application.Application;
          import javafx.application.Platform;
          import javafx.event.ActionEvent;
          import javafx.event.EventHandler;
          import javafx.scene.Group;
          import javafx.scene.Node;
          import javafx.scene.Scene;
          import javafx.scene.control.Button;
          import javafx.scene.input.MouseEvent;
          import javafx.scene.layout.StackPane;
          import javafx.scene.paint.Color;
          import javafx.scene.shape.CircleBuilder;
          import javafx.scene.shape.Rectangle;
          import javafx.scene.shape.RectangleBuilder;
          import javafx.scene.text.Text;
          import javafx.stage.Stage;
          import javafx.stage.StageStyle;
          
          public class CustomX extends Application {
          
              @Override
              public void start(Stage primaryStage) {
                  primaryStage.initStyle(StageStyle.TRANSPARENT);
                  Group root = new Group();
                  Scene scene = new Scene(root, 250, 150, Color.rgb(0, 0, 0, 0));
                  Rectangle rec = RectangleBuilder.create().build();
                  root.getChildren().add(rec);
                  rec.widthProperty().bind(scene.widthProperty());
                  rec.heightProperty().bind(scene.heightProperty());
                  CustomExit ce = new CustomExit();
                  ce.setOnMouseClicked(new EventHandler<MouseEvent>() {
                      @Override
                      public void handle(MouseEvent event) {
                          Platform.exit();
                      }
                  });
          
          
                  root.getChildren().addAll(ce);
                  ce.translateXProperty().bind(scene.widthProperty().subtract(15));
                  ce.setTranslateY(10);
                  primaryStage.setScene(scene);
                  primaryStage.show();
              }
          
              public static void main(String[] args) {
                  launch(args);
              }
          
              class CustomExit extends Group {
          
                  public CustomExit() {
          
                      Node closeButton = CircleBuilder.create()
                              .centerX(5)
                              .centerY(0)
                              .radius(7)
                              .fill(Color.rgb(255, 255, 255, .80))
                              .build();
                      Node closeText = new Text(2, 4, "X");
          
                      getChildren().addAll(closeButton, closeText);
          
          
          
                  }
              }
          }
          • 2. Re: A javaFX Stage could be both StageStyle.UTILITY and StageStyle.TRANSPARENT
            SlashWang
            Thank you, But you may mistake. StageStyle.TRANSPARENT can't make my popup stage not shown on the windows' task bar below, Only stageStyle.UTILITY can satisfy. So i need a popup stage with both stageStyle.UTILITY and transparent background(no default close button).
            • 3. Re: A javaFX Stage could be both StageStyle.UTILITY and StageStyle.TRANSPARENT
              SlashWang
              Already OK!
              invoke dialogStage.initOwner(parentStage)
              http://docs.oracle.com/javafx/2/api/javafx/stage/Stage.html#initOwner%28javafx.stage.Window%29


              Thanks for:
              Re: What's the best way to create a Dialog