0 Replies Latest reply: Nov 13, 2012 8:45 AM by Kishori Sharan RSS

    VBox does not compute its size properly when a Group is used

    Kishori Sharan
      I am adding four Buttons - b1, b2, b3, and b4 - to a VBox and adding the VBox to a scene. b1 has an effect and b3 has an effect and a rotation. When I add b1 and b3 in two different Groups and add those Groups to the VBox, stage does not compute its size proeperly until I call stage.sizeToScene() method after I show the stage. Calling this method before showing the stage has no effect.

      I noticed another difference. When I use b1, b2, b3 and b4 without placing them in a Group, they have the same layoutBounds, as expected. When I add b1 and b3 in Groups, b1 and b3 have different layoutBounds from b2 and b4 that is not expected - particularly the height of the buttons in the Group changes.

      Can someone point me to FX documentation that explains this behavior?

      To see teh different behavior, use one of the statements at a time.

      root.getChildren().addAll(new Group(b1), b2, new Group(b3), b4);
      root.getChildren().addAll(b1, b2, b3, b4);

      // LayoutBoundsTest.java
      package test;
      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.effect.DropShadow;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;
      public class LayoutBoundsTest extends Application {
           public static void main(String[] args) {
           public void start(Stage stage) {
                // Create a drop shadow effect
                DropShadow dsEffect = new DropShadow();
                // Have b1 with a drop shadow effect
                Button b1 = new Button("Close");
                Button b2 = new Button("Close");
               // Have b3 with a drop shadow effect and a 30 degree rotation
                Button b3 = new Button("Close");
                Button b4 = new Button("Close");
                VBox root = new VBox();          
                root.getChildren().addAll(new Group(b1), b2, new Group(b3), b4);
                //root.getChildren().addAll(b1, b2, b3, b4);
                Scene scene = new Scene(root);
                stage.setTitle("Testing LayoutBounds");          
                                      // I have to use sizeToScene() after showing the stage when I use Groups for b1 and b3
                System.out.println("b1=" + b1.getLayoutBounds());
                System.out.println("b2=" + b2.getLayoutBounds());
                System.out.println("b3=" + b3.getLayoutBounds());
                System.out.println("b4=" + b4.getLayoutBounds());