2015-03-13 34 views
0

我想在JavaFX中創建一個UI,它應該有兩列和一行。該行應該從頂部到底部(100%高度),並且列應分別爲80%和20%寬。在第一列中,我創建了一個textarea,而第二列中有一個帶多個按鈕的側欄。如何在javafx中創建一個跨越全高的textarea和側欄?

我面臨的問題是textarea沒有達到全高。我可以改變像素的高度,但我想改變百分比。我嘗試添加RowConstraint,但它不起作用。任何想法我應該如何繼續?

public void start(Stage primaryStage) 
{ 
    primaryStage.setTitle("Particles"); 
    primaryStage.setResizable(false); 

    GridPane grid = new GridPane(); 
    grid.setVgap(10); 
    grid.setHgap(10); 

    RowConstraints row1 = new RowConstraints(); 
    row1.setPercentHeight(100); 

    ColumnConstraints column1 = new ColumnConstraints(); 
    column1.setPercentWidth(80); 
    ColumnConstraints column2 = new ColumnConstraints(); 
    column2.setPercentWidth(20); 

    TextArea environment = new TextArea(); 
    grid.add(environment, 0, 0); 

    Button start = new Button("START"); 
    HBox hbBtn = new HBox(10); 
    hbBtn.setAlignment(Pos.CENTER); 
    hbBtn.getChildren().add(start); 
    grid.add(hbBtn, 1, 0); 

    Scene scene = new Scene(grid, 725, 500); 
    primaryStage.setScene(scene); 

    primaryStage.show(); 
} 

我的輸出:

enter image description here

回答

3

您需要添加的TextField作爲Always

GridPane.setVgrow(environment, Priority.ALWAYS); 

在代碼中Vgrow Priority

TextArea environment = new TextArea(); 
grid.add(environment, 0, 0); 
GridPane.setVgrow(environment, Priority.ALWAYS); 

輸出:

enter image description here

相關問題