繁体   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