0

I am trying to make the AnchorPane resize with its parent JFXDialoglayout. I tried this in scene builder, but wouldn't let me position/resize it correctly. Now I am trying to do it manually instead as seen below. As seen in the code I tried to bind the width and height of the AnchorPane to the JFXDialoglayout, but this did still not work. I also tried setting the pref height/width of them both equally, still did not work. The problem is that the height of the AnchorPane is smaller than the JFXDialogLayout but the width is the same. How do I make the heights equal?

private JFXDialogLayout getDialogLayout() {
    JFXDialogLayout layout = new JFXDialogLayout();
    layout.setPrefWidth(600);
    layout.setPrefHeight(300);
    AnchorPane pane = new AnchorPane();
    pane.prefHeightProperty().bind(layout.prefHeightProperty());
    pane.prefWidthProperty().bind(layout.prefWidthProperty());
    Label heading = new Label("Heading");
    Text body = new Text("This is the body of the dialog.");
    JFXButton button = new JFXButton("ACCEPT");

    pane.getChildren().addAll(heading, body, button);
    layout.getChildren().addAll(pane);
    return layout;
}

1 Answers1

0

I have been making JavaFX apps using SceneBuilder and Netbeans for quite some time. What you are trying to do, can be done easily at the Tab "Layout" and more specific in the tab "Anchor Pane Constraints". Inside the four boxes you have to put the standard distance you like, between the Hbox sides and the Anchor Pane outer sides. Please, check the screenshot below, with my example for a Horizontal Box inside an Anchor Pane. The HBox gets smaller or bigger when the user resizes the Anchor Pane.

SceneBuilder screenshot

  • Thanks for the answer. Maybe I wasn't clear in my question, but the JFXDialogLayout is the parent here, not the AnchorPane. Everything inside the AnchorPane scales fine, but not the AnchorPane itself. – Vetle Hjelmtvedt Mar 20 '19 at 20:06