B4J Question close TabPage

madru

Active Member
Licensed User
Longtime User
Hi,

I like to close a TabPage in code by name, no idea how :(
B4X:
Sub CloseTab(inp As String)
    For Each v As Node In MainForm.RootPane.GetAllViewsRecursive
        If v Is TabPane Then
            Dim a As TabPane
            a = v
            Dim l As List
            l.Initialize
            l.AddAll(a.Tabs)
            Dim x As Int = 0
            For x = 0 To l.Size - 1
                Dim az As TabPage = l.Get(x)
                If az.Text = inp Then
            'close this Tab
                End If
            Next
        End If
    Next
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this sub to close a tab:
B4X:
Sub MainForm_MouseClicked (EventData As MouseEvent)
   CloseTab(TabPane1.Tabs.Get(1))
End Sub

Sub CloseTab (tb As TabPage)
   Dim jo As JavaObject = tb
   jo = jo.RunMethodJO("getTabPane", Null).RunMethodJO("getSkin", Null).RunMethodJO("getBehavior", Null)
   jo.RunMethod("closeTab", Array(tb))
End Sub

Find a tab based on its text:
B4X:
Sub TabByTitle(tp As TabPane, Title As String) As TabPage
   For Each tb As TabPage In tp.Tabs
     If tb.Text = Title Then Return tb
   Next
   Return Null
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
THX

next time I will have look in the Java doc ((TabPaneSkin) getTabPane().getSkin()).getBehavior(); ;)
 
Upvote 0
Top