B4J Question initializing a RadioButton resets the form BackColor ?

a n g l o

Active Member
Licensed User
Longtime User
hello,
not using the designer (all layouts removed).
try this code on a new project :
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private rb As RadioButton
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.BackColor=fx.Colors.Yellow
    MainForm.Show
    rb.Initialize("rb")
End Sub
without the last line, the form is yellow. the last line resets it to default gray that can't be changed anymore.
am i doing something wrong ?
Thank you
 

stevel05

Expert
Licensed User
Longtime User
Not sure why that happens, but this works:

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private rb As RadioButton
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    CSSUtils.SetBackgroundColor(MainForm.RootPane,fx.Colors.Yellow)
    rb.Initialize("rb")
    MainForm.RootPane.AddNode(rb,0,0,30,30)
End Sub
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
Thank You !
yes that works (the AddNode line is not relevant, it works without it too).
so instead of
B4X:
MainForm.BackColor=fx.Colors.Yellow
i have to write
B4X:
CSSUtils.SetBackgroundColor(MainForm.RootPane,fx.Colors.Yellow)
and that fixed it.
ok and thanks again !
however, i still prefer to understand why ALREADY yellow form becomes gray like that.
Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Form.BackColor shouldn't be used in most cases. You should instead change the color of the root pane(l).
B4X:
Sub Process_Globals
    Private MainForm As Form
    Private xui As XUI
    Private rb As RadioButton
End Sub


Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Show
    Dim root As B4XView = MainForm.RootPane
    root.Color = xui.Color_Yellow
    rb.Initialize("rb")
End Sub

There is a strange issue here however it will work fine once you set the root panel color.
 
Upvote 0
Top