Label prefHeight vs wrapText

Werner Lehmann lehmann at media-interactive.de
Thu Feb 5 16:12:15 UTC 2015


Sorry to dig up this old thread. Just wanted to mention a much simpler 
workaround if a label inside a vbox does not wrap its text:

label.setMinHeight(Region.USE_PREF_SIZE);

As before the trick is to prevent vbox from reducing the label height 
below its pref height to preserve the wrapping - even if other children 
of the vbox need to be shrunk.

Werner

On 28.05.2014 18:10, Werner Lehmann wrote:
> Martin,
>
> thanks for the explanation. Feels good to finally understand this ;-)
> And while I created a ticket as per your suggestion...
>
>     [#RT-37309] VBox: vshrink layout hint similar to vgrow
>
> ...it seems I can use this as a workaround:
>
>>      label1.minHeightProperty().bind(Bindings.createDoubleBinding(
>>          () -> label1.prefHeight(vbox.getWidth()),
>>          vbox.widthProperty()));
>
> Maybe something similar could be made available per label boolean
> property. So basically the ability to ask a label to consider wrapping
> when calculating its minHeight... I can imagine that this might have
> made more sense as a default behavior: if people explicitly ask for
> wrapping text, they would probably accept a larger minHeight.
>
> Werner


More information about the openjfx-dev mailing list