StackPane

StackPane 以一種從後到前的方式展示它的孩子。

子項的 z 順序由子列表的順序定義(可通過呼叫 getChildren 訪問):第 0 個子項是堆疊頂部的最後一個子項。

stackpane 嘗試調整每個子節點的大小以填充其自己的內容區域。如果孩子無法調整大小以填充 StackPane 的區域(因為它不可調整大小或其最大大小阻止它),那麼它將使用 stackpane 的 alignmentProperty 在區域內對齊,預設為 Pos.CENTER.

// 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);

StackOverflow 文件