我在JavaFX中创建了一个基本布局。如何让左下方的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();
}
屏幕截图:
答案 0 :(得分:1)
您需要使用AnchorPane并设置适当的约束以按您希望的方式拉伸TextArea
答案 1 :(得分:0)
感谢您的帮助。我只使用了一个带有VBoxes的边框,而TOP列表只有一个VGow。