B4J Question [Solved] [B4J] SetFormStyle error

Aldo's

Active Member
Licensed User
I wrote this code:
B4X:
Private Sub B4XPage_Appear
    B4XPages.setTitle(Me,"Pippo")
    B4XPages.GetNativeParent(Me).WindowHeight=400
    B4XPages.GetNativeParent(Me).WindowWidth=400
    B4XPages.GetNativeParent(Me).Resizable=False
    B4XPages.GetNativeParent(Me).SetFormStyle("UTILITY")
    Dim MyColors(3) As Int = Array As Int(xui.Color_Yellow, xui.Color_ARGB(255,169,255,169), xui.Color_ARGB(255,169,255,250))
    SQL1.InitializeSQLite(Main.DbDir,Main.DbFile,False)
    RS1=SQL1.ExecQuery("SELECT * FROM Pippo WHERE ID = " & Main.iID & "")
    Do While RS1.NextRow
        Dim iCol As Int=RS1.GetInt("colore")-1
        Root.Color=MyColors(iCol)
        lblTitolo.As(Label).Text=RS1.GetString("titolo")
        lblTesto.As(Label).Text=RS1.GetString("testo")
    Loop
End Sub
When I launch the app it gives me this error:
Error occurred on line: 306 (B4XPagesManager)
java.lang.IllegalStateException: Cannot set style once stage has been set visible
at javafx.graphics/javafx.stage.Stage.initStyle(Stage.java:484)
at anywheresoftware.b4j.objects.Form.SetFormStyle(Form.java:278)
at b4j.example.postit._b4xpage_appear(postit.java:79)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:509)
at anywheresoftware.b4a.keywords.Common.access$0(Common.java:489)
at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:563)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)

What am I doing wrong?
 

Aldo's

Active Member
Licensed User
Can I try to insert SetFormStyle in B4XPage_Create?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can I try to insert SetFormStyle in B4XPage_Create?
Based on the Error
Cannot set style once stage has been set visible
it can not been set after it was visible once. Guess you have to set it when the page are created. And only ONCE.
 
Upvote 0

Aldo's

Active Member
Licensed User
it can not been set after it was visible once. Guess you have to set it when the page are created. And only ONCE.
Yes, the B4XPage_Created is invoked before display. Can I put the SetFormStyle there?
 
Upvote 0

Aldo's

Active Member
Licensed User
Yes, the B4XPage_Created is invoked before display. Can I put the SetFormStyle there?
In B4XPage_Create it works.
Thank's
 
Upvote 0

Aldo's

Active Member
Licensed User
I retry and it works.
 
Upvote 0
Top