1

I am currently developing a messenger in javafx. my general layout is a gridpane with a customized Vbox containing a ListView and a Textfield. The problem is that as you can see below there is a big emty area beneath the textfield. I already tried setting the rowspan to 2, which didn't work.

here

The important Code:

Main:

chatBox = new ChatBox();
gridPane.add(chatBox, 1, 0, 1, 2);

ChatBox(extends Vbox):

private static ListView<Message> messages;
private TextField inputField;

public ChatBox() {
    inputField = new TextField();
    messages = new ListView<>();
    init();
    getChildren().addAll(messages, inputField);
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Raffael
  • 33
  • 5

3 Answers3

3

Try adding this in the ChatBox class:

 VBox.setVgrow(messages, Priority.ALWAYS);

And add this in the main class:

GridPane.setVgrow(chatBox, Priority.ALWAYS);
SriAji
  • 101
  • 6
1

You need to set the vgrow using RowConstraints. Assuming your first row contains the ListView that is supposed to take all the available space:

RowConstraints constraints = new RowConstraints();
constraints.setVgrow(Priority.ALWAYS);
gridPane.getRowConstraints().addAll(constraints, new RowConstraints());
fabian
  • 80,457
  • 12
  • 86
  • 114
0

In order to force the list view to take all the height available in its parent, you can use the following method:

messages.setMaxHeight(Double.MAX_VALUE);

If the problem comes from the VBox, its maxHeight can also be modified with the same method.

William A.
  • 425
  • 5
  • 14
  • i tried it with the Vbox, the ListView and the Textfield and it didn't work – Raffael May 14 '19 at 09:31
  • Did you try it with all of them at the same time? You must set this property only for the VBox and ListView, otherwise the effect will be canceled. Could you retry it with setPrefHeight ? – William A. May 14 '19 at 09:55