0

我有这个代码(简化/缩短/伪):

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

我希望背景/堆栈窗格覆盖整个窗口(在背景中,惊喜),并且覆盖/网格覆盖背景的一部分。问题是,当我将 ImageView 添加到 StackPane 时,只显示图像而没有其他内容。叠加层不可见。我尝试过overlay.toFront、overlay.preferredHeight 和background.toBack,但没有成功。

4

1 回答 1

1

尝试将边框窗格放入堆栈窗格,而不是相反,然后确保将图像添加为堆栈窗格子项的第一个元素。

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

或者,只需使用 aBorderPane作为根并以通常的方式添加节点。然后,在外部样式表中,执行

.root {
  -fx-background-image: url(relative/path/to/image);
}
于 2014-10-08T19:29:57.000 回答