B4J Question Get Current Form issue

invocker

Active Member
in this sub from erel to get Get Current Form
B4X:
Public Sub GetCurrentForm As Form
    Dim UninitializedForm As Form
    Dim x As JavaObject
    Dim stage As JavaObject = x.InitializeStatic("anywheresoftware.b4a.objects.B4XViewWrapper$XUI").RunMethod("findActiveStage", Null)
    If stage.IsInitialized = False Then Return UninitializedForm
    Dim scene As JavaObject = stage.RunMethod("getScene", Null)
    Dim pane As B4XView = scene.RunMethod("getRoot", Null)
    Dim a As JavaObject
    Return a.InitializeStatic("anywheresoftware.b4a.AbsObjectWrapper").RunMethodJO("getExtraTags", Array(pane)).RunMethod("get", Array("form"))
End Sub

B4X:
Dim frm As Form = GetCurrentForm
If frm.IsInitialized Then
    Log(frm.Title)
End If

i create a sub to add a lotoff form but the problem that i can't check if it open or not
B4X:
Sub showForm(layout As String,event As String,Title As String,width As Int ,height As Int)
    Dim frmshowing As Boolean=False
    Dim frm As Form = GetCurrentForm
    If frm.IsInitialized Then
        Log("GetCurrentForm "&frm.Title)' the second form is open but get mainform title
        If frm.Title=Title Then
            Log("form is open")
            frmshowing=True
        Else
            Log("form is not open")
            frmshowing=False
        End If
    End If
    If frmshowing  = False Then
        Dim FMF As Form
        FMF.Initialize(event, width, height)
        FMF.RootPane.LoadLayout(layout)
        FMF.Title = Title
        FMF.Show
    End If
 

stevel05

Expert
Licensed User
Longtime User
Have you tried frm.Visible ? Does that not work?

Although the current form is always likely to be Visible. And you could end up creating a duplicate forms.

What are you trying to do?
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are running JavaFX 9+ the attached is probably what you are after.

It creates the Mainform and a test form, which is Iconified (minimized) just for testing.

The GetWindows sub returns all forms (as Stage Objects) that are currently visible i.e. shown and not closed. Documentation here
Stage Documentation is here.
 

Attachments

  • Currentform.zip
    2.7 KB · Views: 30
Last edited:
Upvote 0

invocker

Active Member
thank you the form it not close it hide for that your option to test as visible think it work I resolve this by add form created in map using their title and when it close i get the title form from the sender then remove from map and it work
 
Upvote 0
Top