I want to show text of unknown length in a window. The text should be wrapped if it reaches the border of the window. The initial height of the window should match the height of the text. And if the user resizes the window, the width of the text should also be changed.
How can I achieve this in JavaFX without eventHandlers?
If I use a Label, the text is wrapped and also changes its width, but the initial height of the window does not fit the entire text, so the text is clipped.
If I use Text (Text-tag), I need to specify a wrapping width. The window´s height is correct, but if I resize the window, the width of the text does not change.
In case, you want to use a
Text
you can bind itswrappingWidthProperty
to thescenes's widthProperty
.Similarly, in case you want to use a
Label
, you can bind itsprefHeightProperty
with thescene's heightProperty
.