StackPane
lays out its children in a back-to-front stack.
The z-order of the children is defined by the order of the children list (accessible by calling getChildren
): the 0th child being the bottom and last child on top of the stack.
The stackpane attempts to resize each child to fill its own content area. In the case if a child cannot be resized to fill the area of the StackPane
(either because it was not resizable or its max size prevented it) then it will be aligned within the area using the alignmentProperty
of the stackpane, which defaults to Pos.CENTER.
Example
// Create a StackPane
StackPane pane = new StackPane();
// Create three squares
Rectangle rectBottom = new Rectangle(250, 250);
rectBottom.setFill(Color.AQUA);
Rectangle rectMiddle = new Rectangle(200, 200);
rectMiddle.setFill(Color.CADETBLUE);
Rectangle rectUpper = new Rectangle(150, 150);
rectUpper.setFill(Color.CORAL);
// Place them on top of each other
pane.getChildren().addAll(rectBottom, rectMiddle, rectUpper);