So i have this application that gets some data and shows a graph!
When i start my program the graph data and the line chart is not created and therefore my program looks like this:

then when i press the “Hent data” button then my line graph is created and added on the center of the borderpane this makes the gui to look like this:

As you can see the application stage do not size to fit all the components.
However if i start the program up by creating a random graph (and not changing the size) the program will look like this:

in all of the examples my main stage code looks like this:
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
bp = new BorderPane();
bp.setTop(createTopPane());
Group root = new Group();
root.getChildren().add(bp);
bp.setCenter(createCenter());
AnchorPane leftPane = new AnchorPane();
leftPane.setPrefWidth(20);
Separator vSeparator = new Separator(Orientation.VERTICAL);
bp.setRight(leftPane);
Scene scene = new Scene(root);
scene.getStylesheets().addAll("test.css", "calendarstyle.css");
primaryStage.setScene(scene);
primaryStage.setMinHeight(500);
primaryStage.setMinWidth(527);
primaryStage.show();
}
How can i make sure that the stage stays the size it should be to fit the graph even if the graph is not yet created?
Please note that i have already tried to change the primaryStage size when i click the button however this did not solve the problem
Use the
AnchorPane.setLeftAnchor(javaFxNode, 0.0);andAnchorPane.setRightAnchor(javaFxNode, 0.0);static methods. A value of 0 in both should ‘stick’ the sides of your chart to its container. Of course you can usesetTopAnchorandsetBottomAnchoras well for the same issue in height.