B4J Question [SOLVED] How to disable Label autoresize when increasing TextSize

Sagenut

Expert
Licensed User
Longtime User
Hi!
I searched in the forum but I found nothing about it, maybe wrong research.
In B4J a label automatically increase its size to show all the text when TextSize increase.
I would like to disable this and make Label in B4J to act like Labels in B4A.
I think that it's needed something about CSS but I am unable to find it, or make what I found to work.
Thank You!
 
Solution
Apparently, having tried it, that is not enough. You need to set minHeight / width, prefHeight / width and maxHeight / width to the same values.

As PrefHeight and Width are already set this works for me:

B4X:
Public Sub SetLblFixedSize(Lbl As Label)
    Dim MaxHeight As Double = Lbl.PrefHeight
    Dim MaxWidth As Double = Lbl.PrefWidth
    Lbl.as(JavaObject).RunMethod("setMaxHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMaxWidth",Array(MaxWidth))
    Lbl.as(JavaObject).RunMethod("setMinHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMinWidth",Array(MaxWidth))
End Sub

Usage
B4X:
SetLblFixedSize(Label1)

stevel05

Expert
Licensed User
Longtime User
Try setting maxheight and maxwidth, you can do this with JavaObject:

B4X:
Dim MaxHeight as Double = lbl.as(B4xView).Height
Dim MaxWidth as Double = lbl.as(B4xView).Width
lbl.as(JavaObject).RunMethod("setMaxHeight",Array(MaxHeight))
lbl.as(JavaObject).RunMethod("setMaxWidth",Array(MaxWidth))
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Try setting maxheight and maxwidth, you can do this with JavaObject:

B4X:
Dim MaxHeight as Double = lbl.as(B4xView).Height
Dim MaxWidth as Double = lbl.as(B4xView).Width
lbl.as(JavaObject).RunMethod("setMaxHeight",Array(MaxHeight))
lbl.as(JavaObject).RunMethod("setMaxWidth",Array(MaxWidth))
Unluckily it seems not to work.
Thanks
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Apparently, having tried it, that is not enough. You need to set minHeight / width, prefHeight / width and maxHeight / width to the same values.

As PrefHeight and Width are already set this works for me:

B4X:
Public Sub SetLblFixedSize(Lbl As Label)
    Dim MaxHeight As Double = Lbl.PrefHeight
    Dim MaxWidth As Double = Lbl.PrefWidth
    Lbl.as(JavaObject).RunMethod("setMaxHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMaxWidth",Array(MaxWidth))
    Lbl.as(JavaObject).RunMethod("setMinHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMinWidth",Array(MaxWidth))
End Sub

Usage
B4X:
SetLblFixedSize(Label1)
 
Upvote 0
Solution

Sagenut

Expert
Licensed User
Longtime User
Apparently, having tried it, that is not enough. You need to set minHeight / width, prefHeight / width and maxHeight / width to the same values.

As PrefHeight and Width are already set this works for me:

B4X:
Public Sub SetLblFixedSize(Lbl As Label)
    Dim MaxHeight As Double = Lbl.PrefHeight
    Dim MaxWidth As Double = Lbl.PrefWidth
    Lbl.as(JavaObject).RunMethod("setMaxHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMaxWidth",Array(MaxWidth))
    Lbl.as(JavaObject).RunMethod("setMinHeight",Array(MaxHeight))
    Lbl.as(JavaObject).RunMethod("setMinWidth",Array(MaxWidth))
End Sub

Usage
B4X:
SetLblFixedSize(Label1)
Yes!
It works.
Thank you @stevel05 !
 
Upvote 0
Top