我目前正在用 javafx 开发一个 Messenger。我的总体布局是一个带有自定义 Vbox 的网格 Pane ,其中包含一个 ListView 和一个 Textfield。问题是,正如您在下面看到的,文本字段下方有一个很大的空白区域。我已经尝试将 rowspan 设置为 2,但没有用。
重要代码:
主要内容:
chatBox = new ChatBox();
gridPane.add(chatBox, 1, 0, 1, 2);
聊天框(扩展 Vbox):
private static ListView<Message> messages;
private TextField inputField;
public ChatBox() {
inputField = new TextField();
messages = new ListView<>();
init();
getChildren().addAll(messages, inputField);
}
最佳答案
尝试在 ChatBox 类中添加:
VBox.setVgrow(messages, Priority.ALWAYS);
在主类中添加:
GridPane.setVgrow(chatBox, Priority.ALWAYS);
关于java - Vbox 没有填满网格 Pane 中的所有可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56126553/