4 Replies Latest reply: Nov 30, 2011 10:46 AM by palban RSS

    How to create a rounded window?

    palban
      As Title ;)

      I need to create a rounded undecorated window.

      Thanks in advanced
        • 1. Re: How to create a rounded window?
          David Grieve
          import javafx.application.Application;
          import javafx.scene.Group;
          import javafx.scene.Scene;
          import javafx.scene.paint.Color;
          import javafx.scene.shape.Rectangle;
          import javafx.stage.Stage;
          import javafx.stage.StageStyle;
          
          public class Main extends Application {
          
          
              @Override public void start(Stage stage) {
                  
                  Rectangle rect = new Rectangle(600,450);
                  rect.setArcHeight(50);
                  rect.setArcWidth(50);
                  rect.setStroke(Color.BLACK);
                  rect.setFill(Color.rgb(255, 0, 0, .5));
                  
                  Group group = new Group();
                  group.getChildren().add(rect);
                  
                  Scene scene = new Scene(group);
                  scene.setFill(Color.TRANSPARENT);
                  
                  stage.initStyle(StageStyle.TRANSPARENT);
                  stage.setScene(scene);
                  stage.show();
              }
          
              /**
               * @param args the command line arguments
               */
              public static void main(String[] args) {
                  Application.launch(args);
              }
          }
          You could use Region or Stack or some other layout container for the scene root and then use CSS to style the window in a bazillion different ways.

          Edited by: dgrieve on Nov 30, 2011 7:04 AM
          • 2. Re: How to create a rounded window?
            palban
            Thank u very much.
            Your answer helped me ;)

            I have just another question:

            - Can i create a node with only one rounded angle?

            Edited by: 899956 on 30-nov-2011 8.08
            • 3. Re: How to create a rounded window?
              David Grieve
              If you use a Region or a Stack or some other layout container, then you can use css to style the corners. For example, if you used a Stack and gave the Stack an id of "foo", then you could do this in CSS:

              #foo { -fx-background-radius: 0 50 0 0; }

              This would give you a rectangle with upper left corner square, upper right corner 50px, lower right and lower left corners square.
              • 4. Re: How to create a rounded window?
                palban
                Thank u very much. I just solved reading css guide