2013-11-27 56 views
1

我在JavaFX中创建了一个基本布局。如何获取左下角的TextArea以调整大小以使用完整的可用空格?目前它只是水平调整大小,而不是垂直调整大小。水平和垂直调整TextArea的大小

代码:

public VBox addVBoxLeft() { 

    VBox vBoxLeft = new VBox(); 
    vBoxLeft.setSpacing(10); 
    vBoxLeft.setPadding(new Insets(10)); 

    //Content vBoxLeft 
    Text titleGamesAvailable = new Text("Games available:"); 
    titleGamesAvailable.setFont(Font.font("Arial", FontWeight.BOLD, 14)); 
    TextArea chatHistory = new TextArea(); 
    chatHistory.setText("..."); 
    chatHistory.setEditable(false); 
    chatHistory.setWrapText(true); 
    chatHistory.setPrefColumnCount(2); 

    vBoxLeft.setAlignment(Pos.TOP_LEFT); 
    vBoxLeft.getChildren().addAll(titleGamesAvailable, availableGamesList(),chatHistory); 

    return vBoxLeft; 
} 

private ListView<String> availableGamesList() { 
    this.availableGamesListView = new ListView<String>(); 
    availableGamesListView.setItems(gamelist); 
    return availableGamesListView; 
} 

public VBox addVBoxRight() { 
    VBox vboxRight = new VBox(); 
    vboxRight.setPadding(new Insets(10)); 
    vboxRight.setSpacing(8); 

    Text title = new Text("Users online:"); 
    title.setFont(Font.font("Arial", FontWeight.BOLD, 14)); 

    this.userOnlineListView = new ListView<String>(); 
    this.userlist = FXCollections.observableArrayList(); 
    userOnlineListView.setItems(userlist); 
    VBox.setVgrow(userOnlineListView, Priority.ALWAYS); 
    vboxRight.getChildren().addAll(title, userOnlineListView); 

    return vboxRight; 
} 

private void _showView() { 
    this.primaryStage = new Stage(); 
    primaryStage.setTitle("Carcassonne"); 

    // Als Grundlayout dient Borderpane 
    BorderPane border = new BorderPane(); 
    border.setPrefSize(1024, 768); 

    // HBox hbox = addHBox(); 
    border.setTop(addHBoxTop()); 
    border.setCenter(addVBoxLeft()); 
    border.setRight(addVBoxRight()); 


    Scene scene = new Scene(border); 

    primaryStage.setScene(scene); 
    primaryStage.setTitle("Lobby"); 
    primaryStage.setMinHeight(600); 
    primaryStage.setMinWidth(800); 
    primaryStage.setFullScreen(false); 
    primaryStage.show(); 
} 

截图:

enter image description here

回答

1

您需要使用AnchorPane并设置相应的约束,以舒展的TextArea你想

+1

“使用AnchorPane”。你可以用代码示例来详细说明吗? – HEATH3N

0

感谢的方式你帮帮我。我只用VBox替代了一个borderpane,只有TOP列表中有一个VGow。