我有以下代码(简化/简写/伪):
StackPane background = new StackPane();
GridPane overlay = new GridPane();
BorderPane pane = new BorderPane(background);
pane.setLeft(overlay);我希望后台/堆栈窗格覆盖整个窗口(在后台,惊喜),而overlay/Grid则覆盖部分背景。问题是,当我将一个ImageView添加到StackPane中时,图像就会显示出来,而没有其他任何东西。覆盖是不可见的。我试过overlay.toFront、overlay.preferredHeight和background.toBack,但没有成功。
发布于 2014-10-08 19:29:57
尝试将边框窗格放入堆栈窗格,而不是反过来,然后确保将图像添加为堆栈窗格的子元素的第一个元素。
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);
}https://stackoverflow.com/questions/26264844
复制相似问题