2012-11-21 52 views
0

所以我有這樣的應用程序,它得到了一些數據,並顯示一個圖形不調整!JavaFX的階段,當組件添加

當我開始我的程序的圖形數據和不創建線圖,因此我的程序是這樣的:

enter image description here

然後當我按下「恆通數據」按鈕,然後我的線圖被創建並添加到邊界窗格的中心,這使得gui看起來像這樣: enter image description here

正如您所看到的應用程序階段不適合所有組件。

但是如果我啓動該程序通過創建一個隨機圖(在不改變大小)的計劃將是這樣的:

enter image description here

在我所有的主舞臺代碼如下例子這樣的:

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大小當我點擊按鈕,但是這並沒有解決問題

+0

任何人都知道我能得到添加的組件即使在首選大小? –

回答

2

使用AnchorPane.setLeftAnchor(javaFxNode, 0.0);AnchorPane.setRightAnchor(javaFxNode, 0.0);靜態方法。 0在這兩個值應「堅持」你的圖表的邊到其容器。當然,你可以使用setTopAnchorsetBottomAnchor以及在高度相同的問題。

+0

謝謝您的答覆,我會檢查,看看這是否正常工作,當我回來的明天而努力 –