B4J Question Font in the internal designer

Aldo's

Active Member
Licensed User
Hello, is it possible to add a font (.ttf) in the internal designer?
Thank you
 

Aldo's

Active Member
Licensed User
I have use this code in Sub b4X_Appear:
B4X:
    Dim fPippo As B4XFont
    Dim fx As JFX
    fPippo=xui.CreateFont(fx.LoadFont(Main.DBDir,"PIPPO.TTF",15),15)
    txtNome.As(B4XView).Font=fPippo
but when i use txtNome the font is DEFAULT
where am I wrong?
 
Last edited:
Upvote 0

Aldo's

Active Member
Licensed User
This is the font file
 

Attachments

  • MAGIC.zip
    28.2 KB · Views: 115
Upvote 0

zed

Active Member
Licensed User
Try this
B4J:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As Label
    Private fPippo As B4XFont
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
   
    Dim fx As JFX
    fPippo=xui.CreateFont(fx.LoadFont(File.DirAssets,"MAGIC.TTF",15),15)
    Label1.As(B4XView).Font=fPippo
   
End Sub

Make sure the TTF matches correctly. The given file does not match the code
 

Attachments

  • FontTTF.zip
    36.5 KB · Views: 93
Upvote 0

Aldo's

Active Member
Licensed User
I added something to the code and I saw that it works with the label, but it doesn't work with the textfield.
This is the code I wrote:
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As Label
    Dim fPippo As B4XFont
    Private TextField1 As TextField
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim fx As JFX
    fPippo=xui.CreateFont(fx.LoadFont(File.DirAssets,"MAGIC.TTF",15),15)
    TextField1.As(B4XView).Font=fPippo
    Label1.As(B4XView).Font=fPippo
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub TextField1_TextChanged (Old As String, New As String)
    Label1.Text=New
End Sub
 
Upvote 0

zed

Active Member
Licensed User
Add this

B4J:
Dim joTF As JavaObject = TextField1
joTF.runMethod("setFont",Array(fx.LoadFont(File.DirAssets,"MAGIC.TTF", 15)))
   
Dim joTA As JavaObject = TextArea1
joTA.runMethod("setFont",Array(fx.LoadFont(File.DirAssets,"MAGIC.TTF", 15)))
 

Attachments

  • FontTTF.zip
    36.8 KB · Views: 112
Last edited:
Upvote 0

Aldo's

Active Member
Licensed User
Even in your code when I open the font file it is correct. But when I write it starts using the default font again.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Have you tried moving
B4X:
Dim fx As JFX

to Class_Globals sub
 
Upvote 0

zed

Active Member
Licensed User
The behavior is weird.
I tried with FocusChanged. But that doesn't change anything.
One view works with focus and the other view does the opposite.
I can't fix the problem.
I don't see where this could come from
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am afraid that it has something to do with the font file.
I tested it with different custom fonts and it works as expected.
But MAGIC.TTF and another one I downloaded from the internet witches-magic.ttf both do not work.

I think that Erel should have a look at this.
 

Attachments

  • CustomFont.zip
    2.3 KB · Views: 108
  • Like
Reactions: zed
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Playing with this I found the following

The font is correctly displayed in the textfield prior to any input into the field. (The prompt is shown in the 'new' font)
After the TextChanged sub is entered, the font defaults back to default.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Isn't that right down here?
1704825633065.png


I am not familiar with B4j.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've got it working with this:
B4X:
CSSUtils.SetStyleProperty(TextField1, "-fx-font-family", $""${MyFont.ToNativeFont.FamilyName}""$)
CSSUtils.SetStyleProperty(TextArea1, "-fx-font-family", $""${MyFont.ToNativeFont.FamilyName}""$)

Looks like a bug in B4XView.SetFont. Please try it.
 
Upvote 0
Top