[英]Javafx stage does not resize when components are added
所以我有這個應用程序獲取一些數據並顯示圖表!
當我啟動程序時,不會創建圖表數據和折線圖,因此我的程序如下所示:
然后當我按下“Hent data”按鈕時,我的線圖被創建並添加到borderpane的中心,這使得gui看起來像這樣:
如您所見,應用程序階段的大小不適合所有組件。
但是,如果我通過創建隨機圖形(而不是更改大小)來啟動程序,程序將如下所示:
在所有示例中,我的主要階段代碼如下所示:
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();
}
即使圖形尚未創建,我如何確保舞台保持適合圖形的大小?
請注意,當我單擊按鈕時,我已經嘗試更改primaryStage大小,但這並沒有解決問題
使用AnchorPane.setLeftAnchor(javaFxNode, 0.0);
和AnchorPane.setRightAnchor(javaFxNode, 0.0);
靜態方法。 兩者中的值均為0,應將圖表的兩側“粘貼”到其容器中。 當然,您也可以使用setTopAnchor
和setBottomAnchor
來處理相同的高度問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.