Hello,
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);
Thanks
Kishori
// 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) {
Application.launch(args);
}
public void start(Stage stage) {
// Create a drop shadow effect
DropShadow dsEffect = new DropShadow();
dsEffect.setOffsetY(15.0);
dsEffect.setOffsetX(15.0);
dsEffect.setColor(Color.DARKGRAY);
// Have b1 with a drop shadow effect
Button b1 = new Button("Close");
b1.setEffect(dsEffect);
Button b2 = new Button("Close");
// Have b3 with a drop shadow effect and a 30 degree rotation
Button b3 = new Button("Close");
b3.setEffect(dsEffect);
b3.setRotate(30);
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.setScene(scene);
stage.setTitle("Testing LayoutBounds");
stage.show();
// I have to use sizeToScene() after showing the stage when I use Groups for b1 and b3
//stage.sizeToScene();
System.out.println("b1=" + b1.getLayoutBounds());
System.out.println("b2=" + b2.getLayoutBounds());
System.out.println("b3=" + b3.getLayoutBounds());
System.out.println("b4=" + b4.getLayoutBounds());
}
}