How to show two lines of a long text? (or: how to measure text height?)

Werner Lehmann lehmann at media-interactive.de
Tue May 22 05:03:19 PDT 2012


Hi,

I need to display the excerpt of a message: at most first two lines with 
maxWidth 400px and an end ellipsis if the message does not fit.

In Win32 API I'd have to do this:
1. Get height of wrapped text with specified width.
2. Get height of a single line of text with the appropriate font.
3. Use maxHeight for two lines, or the full height, whatever is less.

But how can I achieve the same in FX? I don't know what to use as 
maxHeight for a Label. TextArea has a prefRowCount property but no end 
ellipsis, and (worse) it always shows two rows even for shorter 
messages... It also shows a border and a scrollbar but I assume that 
these can be hidden.

Werner


More information about the openjfx-dev mailing list