Hi Werner,
the important min/pref/max height is the one with width parameter as Label is horizontally biased. So while minHeight(width) == 17, prefHeight(width) == 34. But in your case, with ListView's prefHeight == 1000, you'll overflow by over 400px. VBox does evenly subtract these overflow pixels from children until it gets to their minimum. Which happens in case of the Label. Vgrow is ignored when shrinking (see javadoc for setVgrow). Currently, neither VBox nor GridPane allow you define policy for children when the pane is below it's pref size and children need to be shrunk. Seems like a good candidate for a Tweak in JIRA. ;-) If you need to keep your Label at some height, currently you can only raise it's minHeight, but I understand that in this case it may be tricky as it depends on the width.


On 28.5.2014 15:44, Werner Lehmann wrote:

I am stumped. With a label and wrapText=true I am not getting wrapped text when I think I should. Consider this scene (code at bottom):

  - Label, long text, wrapText=true
  - ListView, prefHeight=1000 (too big to fit)

This will not wrap the label text. The VBox gives all room to the listview and keeps the label on a single line. VBox.vgrow does not change this.

Without the prefHeight on the listview I am getting wrapped text. Then, label height is 34 - while its min/pref/max height is all at 17 according to ScenicView.

Why is the label not reporting a pref height of 34?
Why is the vbox sizing the label beyond its max height?

Appreciate any insight because I don't see what's going on.


public class WrapTest extends Application
  public static void main(String[] args)

  public void start(Stage primaryStage) throws Exception
    Label label1 = new Label(Strings.repeat("bla ", 50));

    ListView<String> lv = new ListView<String>();

    VBox vb = new VBox(label1, lv);
    Scene scene = new Scene(vb, 800, 600);

Reply via email to