简体   繁体   English

Javafx BorderPane强制重叠

[英]Javafx BorderPane Force Overlap

I have this code (simplified/shortend/pseudo): 我有以下代码(简化/短路/伪):

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

I want the background/Stack pane to cover the entire window (in the background, surprise), and the overlay/Grid to cover a part of the background. 我希望背景/堆栈窗格覆盖整个窗口(在背景中,令人惊讶),而覆盖/网格覆盖背景的一部分。 The issue is that when I add an ImageView to the StackPane, the image shows up and nothing else. 问题是,当我将ImageView添加到StackPane时,图像显示出来,而没有其他显示。 The overlay is not visible. 叠加层不可见。 I have tried overlay.toFront, overlay.preferredHeight, and background.toBack, with no success. 我尝试了overlay.toFront,overlay.preferredHeight和background.toBack,但没有成功。

Try putting the border pane into the stack pane, instead of the other way around, and then making sure you add the image as the first element of the stack pane's children. 尝试将边框窗格放到堆栈窗格中,而不要反过来,然后确保将图像添加为堆栈窗格的子项的第一个元素。

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

Alternatively, just use a BorderPane as the root and add the nodes in the usual way. 或者,只需使用BorderPane作为根,然后以通常的方式添加节点。 Then, in an external style sheet, do 然后,在外部样式表中,执行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM