B4J Question Changing the text of a label in code

wdegler

Active Member
Licensed User
Longtime User
I wish to have a label in which I can change the text in code. I have done that a lot in B4A but B4J eludes me. I am using JavaFX sceneBuilder 2.0 and wish the scene to have both changeable and unchanged label text. Please let me know what I am doing wrong or not doing. Sample code follows:

Sub AppStart (Form1 AsForm, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Test1Layout") 'Load the layout file.
MainForm.Show

Dim Test1Lbl As Label 'The layout file has the Test1Lbl label with the text "Label"
Test1Lbl.Text="DEF" 'This does not change the label; "Label" still shows.

Dim Lbl As Label 'This label is not in the layout file (in code only)
Lbl.Initialize("") 'This code shows nothing
Lbl.PrefWidth=100
Lbl.PrefHeight=30
Lbl.Left=50
Lbl.Top=5
Lbl.Text="ABC"
End Sub

Walter Degler
 

Daestrum

Expert
Licensed User
Longtime User
I think you have two misunderstandings here.
1, Nodes defined in the designer, I believe have to be defined in the Process_Globals Sub
so you would need to move Text1Lbl definition to there.
2, The code generated label won't show unless you add it to a parent
ie MainForm.RootPane.AddNode(Lbl,50,5,100,30)
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
I think you have two misunderstandings here.
1, Nodes defined in the designer, I believe have to be defined in the Process_Globals Sub
so you would need to move Text1Lbl definition to there.
2, The code generated label won't show unless you add it to a parent
ie MainForm.RootPane.AddNode(Lbl,50,5,100,30)

Thank very much! Your information fixes BOTH misunderstandings. It works now! :)
 
Upvote 0
Top