簡體   English   中英

Javafx BorderPane強制重疊

[英]Javafx BorderPane Force Overlap

我有以下代碼(簡化/短路/偽):

StackPane background = new StackPane();
GridPane overlay = new GridPane();
BorderPane pane = new BorderPane(background);
pane.setLeft(overlay);

我希望背景/堆棧窗格覆蓋整個窗口(在背景中,令人驚訝),而覆蓋/網格覆蓋背景的一部分。 問題是,當我將ImageView添加到StackPane時,圖像顯示出來,而沒有其他顯示。 疊加層不可見。 我嘗試了overlay.toFront,overlay.preferredHeight和background.toBack,但沒有成功。

嘗試將邊框窗格放到堆棧窗格中,而不要反過來,然后確保將圖像添加為堆棧窗格的子項的第一個元素。

GridPane overlay = new GridPane();
BorderPane pane = new BorderPane();
pane.setLeft(overlay);
StackPane background = new StackPane(pane);

// ... 
ImageView imageView = ... ;
background.getChildren().add(0, imageView);

// ...
scene.setRoot(background);

或者,只需使用BorderPane作為根,然后以通常的方式添加節點。 然后,在外部樣式表中,執行

.root {
  -fx-background-image: url(relative/path/to/image);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM