[英]Javafx stage does not resize when components are added
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: 然后当我按下“Hent data”按钮时,我的线图被创建并添加到borderpane的中心,这使得gui看起来像这样:
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 请注意,当我单击按钮时,我已经尝试更改primaryStage大小,但这并没有解决问题
Use the AnchorPane.setLeftAnchor(javaFxNode, 0.0);
使用
AnchorPane.setLeftAnchor(javaFxNode, 0.0);
and AnchorPane.setRightAnchor(javaFxNode, 0.0);
和
AnchorPane.setRightAnchor(javaFxNode, 0.0);
static methods. 静态方法。 A value of 0 in both should 'stick' the sides of your chart to its container.
两者中的值均为0,应将图表的两侧“粘贴”到其容器中。 Of course you can use
setTopAnchor
and setBottomAnchor
as well for the same issue in height. 当然,您也可以使用
setTopAnchor
和setBottomAnchor
来处理相同的高度问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.