Java 水平和垂直调整文本区域的大小

Java 水平和垂直调整文本区域的大小,java,resize,textarea,javafx,Java,Resize,Textarea,Javafx,我用JavaFX创建了一个基本布局。如何使左下角的TextArea调整大小以使用完整的可用空白?目前,它只是水平调整大小,而不是垂直调整大小 守则: public VBox addVBoxLeft() { VBox vBoxLeft = new VBox(); vBoxLeft.setSpacing(10); vBoxLeft.setPadding(new Insets(10)); //Content vBoxLeft Text titleGamesA

我用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();
}
public VBox addVBoxLeft(){
VBox vBoxLeft=新的VBox();
vBoxLeft.setspace(10);
设置填充(新插图(10));
//内容vBoxLeft
Text titleGamesAvailable=新文本(“游戏可用:”);
titleGamesAvailable.setFont(Font.Font(“Arial”,fontwweight.BOLD,14));
TextArea chatHistory=新建TextArea();
chatHistory.setText(“…”);
chatHistory.setEditable(false);
chatHistory.setWrapText(true);
chatHistory.setPrefColumnCount(2);
vBoxLeft.setAlignment(位置左上方);
vBoxLeft.getChildren().addAll(titleGamesAvailable,availableGamesList(),chatHistory);
返回vBoxLeft;
}
私有ListView availableGamesList(){
this.availableGamesListView=新建ListView();
setItems(游戏列表);
返回availableGamesListView;
}
公共VBox addVBoxRight(){
VBox vboxRight=新的VBox();
设置填充(新插图(10));
vboxRight.setspace(8);
文本标题=新文本(“在线用户:”);
title.setFont(Font.Font(“Arial”,fontwweight.BOLD,14));
this.userOnlineListView=新建ListView();
this.userlist=FXCollections.observearraylist();
setItems(userlist);
setVgrow(userOnlineListView,Priority.ALWAYS);
vboxRight.getChildren().addAll(标题,userOnlineListView);
返回vboxRight;
}
私有void_showView(){
this.primaryStage=新阶段();
初级阶段。片名(“卡尔卡松”);
//Als Grundlayout dient边界窗格
BorderPane border=新的BorderPane();
border.setPrefSize(1024768);
//HBox HBox=addHBox();
setTop(addHBoxTop());
setCenter(addVBoxLeft());
setRight(addVBoxRight());
场景=新场景(边框);
初级阶段。场景(场景);
初级阶段。设置标题(“大厅”);
初级阶段。最低设置高度(600);
初级阶段设置最小宽度(800);
primaryStage.setFullScreen(假);
primaryStage.show();
}
截图:


您需要使用Ancorpane并设置适当的约束来按您想要的方式拉伸文本区域

您需要使用Ancorpane并设置适当的约束来按您想要的方式拉伸文本区域

谢谢您的帮助。我使用了一个只有VBox的边框窗格,只有最上面的列表才有VGow。

谢谢您的帮助。我使用了一个只有VBoxe的边框窗格,只有最上面的列表有一个VGow。

“使用AnchorPane”。有没有可能你可以用一个代码示例来详细说明?“使用AnchorPane”。有没有可能你可以用一个代码示例来详细说明?