B4J Question ComboBox and ChoiceBox font size

red30

Well-Known Member
Licensed User
Longtime User
How do I resize the text in a ComboBox and ChoiceBox?
For all elements, I will change the font size in the designer:
B4X:
If ActivitySize>20 Then
    btn.TextSize=16
    lbl.TextSize=16
Else
    btn.TextSize=12
    lbl.TextSize=12
EndIf
But for the ComboBox, I cannot change the font.
I've tried changing the font of this when resizing the form in code, but this doesn't work:
B4X:
lblactsize.Text=ActivitySize 'designer script

Sub frmfirst_Resize (Width As Double, Height As Double)
    If lblactsize.Text>15 Then
        ChB.Style="-fx-font-size: 16;"
    Else
        ChB.Style="-fx-font-size: 12;"
    End If
End Sub
 

behnam_tr

Active Member
Licensed User
Longtime User
you should use cssutils Library

B4X:
Sub MainForm_Resize (Width As Double, Height As Double)

     CSSUtils.SetStyleProperty(ComboBox1,"-fx-font-size",Rnd(10,20))

     CSSUtils.SetStyleProperty(ChoiceBox1,"-fx-font-size",Rnd(10,20))

End Sub
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I hadn't come across using ActivitySize for B4j, but in principle your method works for me.

You should use CSSUtils to change the font size though:
B4X:
CSSUtils.SetStyleProperty(ChB, "-fx-font-size", 16)

Is the eventname of the form correct : frmfirst? Is the sub being called?
 

Attachments

  • ff.zip
    2.2 KB · Views: 325
Last edited:
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I hadn't come across using ActivitySize for B4j, but in principle your method works for me.

You should use CSSUtils to change the font size though:
B4X:
CSSUtils.SetStyleProperty(ChB, "-fx-font-size", 16)

Is the eventname of the form correct : frmfirst? Is the sub being called?
I'll try CSSUtils .
At the beginning when Show is called this code works
B4X:
Public Sub Show   
    If lblactsize.Text>15 Then
        ChB.Style="-fx-font-size: 16;"
    Else
        ChB.Style="-fx-font-size: 12;"
    End If
End Sub
But when the resize is called, the code stops working
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Put a log("Here") statement in the Resize sub, I am guessing it's not being called.
 
Upvote 0
Top