B4J Question Label - set height to max based on content

mfstuart

Active Member
Licensed User
Longtime User
How do you set the height of a Label node, in code, to the height (width is set and cannot change) that will show all content of the label?
I've tried setting the Label.Height and Label.PrefHeight to no avail.

I'm trying to use this with the JFXPrint8 library.

Thanx,
Mark Stuart
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Start by setting Private xui as XUI in Process_Globals (add XUI as library)
With B4XView you have much better control of the dimensions of a label.
With B4Xcanvas you can get the exact height of text.

Typically:
B4X:
    Dim cv As B4XCanvas  'ignore, this doesn't need to be initialized for this purpose
    Dim alablx As B4XView = alabl                    'alabl created with designer or in code'
    alablx.Text = "XXXX"
    alablx.Height = 2 * cv.MeasureText(alablx.Text, alablx.font).Height
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…