简体   繁体   中英

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. The overlay is not visible. I have tried overlay.toFront, overlay.preferredHeight, and background.toBack, with no success.

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. Then, in an external style sheet, do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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