B4J Question Custom Font in Designer

Peter Lewis

Active Member
Licensed User
Longtime User
Hi,
I have placed the font files as per a post by Erel. But the fonts do not appear in the font selection area.

I have restarted b4j but still no luck.

Any ideas ?

Thank you

1641248661599.png
 

MegatenFreak

Active Member
Licensed User
Try doing it with the code (if you haven't already tried!!), putting the font file in the Files folder.
B4X:
    Dim jo As JavaObject = myTextField
    jo.runMethod("setFont",Array(fx.LoadFont(File.DirAssets,"WhiteRabbit.ttf", 15)))

If you don't want to do the lines for every single node, apply it to all the nodes (or those tagged) at once:
B4X:
For Each nd As Node In MainForm.RootPane.GetAllViewsRecursive
    If nd Is Label Then ....
    If nd.tag = "change_me" Then ...
Next
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
B4XView:
B4X:
tf.Font = xui.CreateFont(fx.LoadFont(...), 14)


Only B4A supports adding fonts inside the designer.
I put in the code you suggested after loading the page and restarted the app but the font did not change to the new one

B4X:
Private cmbCustomerList As B4XComboBox  'In Process Globals
cmbCustomerList.mBase.Font = xui.CreateFont(fx.LoadFont(File.DirApp,"Go-Mono.ttf",14),14) ' After Loading the  Layout File in the Initial Sub

It is a B4xComboBox

This is a MonoSpaced font . I had it set to the internal Monospaced font but would like a better fixed typeface for this operation

So I set the Designer back to Default . The new font should be displayed


What I am looking for is something like this but a different monospaced font


Thank you
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Combobox (B4xComboBox) is a different case as it is constructed from multiple views. It's font cannot be set directly so needs to be done using CSS.

This works for me (not cross platform):

B4X:
    fx.LoadFont(File.DirAssets,"Go-Mono.ttf",15)
    Dim L As List
    L.Initialize
    For i = 0 To 10
        L.Add("Item " & i)
    Next
    B4XComboBox1.SetItems(L)
'   B4XComboBox1.cmbBox.Style = $"-fx-font: 15px "Go Mono";"$
'   But it is better to use CSSUtils
    CSSUtils.SetStyleProperty(B4XComboBox1.cmbBox,"-fx-font",$"15px "Go Mono""$)
 
Last edited:
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Combobox (B4xComboBox) is a different case as it is constructed from multiple views. It's font cannot be set directly so needs to be done using CSS.

This works for me (not cross platform):

B4X:
    fx.LoadFont(File.DirAssets,"Go-Mono.ttf",15)
    Dim L As List
    L.Initialize
    For i = 0 To 10
        L.Add("Item " & i)
    Next
    B4XComboBox1.SetItems(L)
'   B4XComboBox1.cmbBox.Style = $"-fx-font: 15px "Go Mono";"$
'   But it is better to use CSSUtils
    CSSUtils.SetStyleProperty(B4XComboBox1.cmbBox,"-fx-font",$"15px "Go Mono""$)
I used the CSS method a lot cleaner

Thank You
 
Upvote 0
Top