B4J Question Add/close Tabpane

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi all,
Based on Erel demo app i try to add / and close a tab (i would like to create an UI interface like a web browser ). Code sniped that i found it's work for close tab , but if i try add a new i got error. Could anybody help me?
Attached you can see the test project.
 

Attachments

  • testTabpane.zip
    3.3 KB · Views: 249

Erel

B4X founder
Staff member
Licensed User
Longtime User
Correct code:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
   MainForm.RootPane.LoadLayout("main")
   MainForm.Show
   Dim jo As JavaObject = TabPane1
   jo.RunMethod("setTabClosingPolicy", Array("ALL_TABS"))
   Dim ev As Object = jo.CreateEventFromUI("javafx.collections.ListChangeListener", "TabsListChanged", Null)
   jo.RunMethodJO("getTabs", Null).RunMethod("addListener", Array(ev))
End Sub
Sub TabsListChanged_Event (MethodName As String, Args() As Object) As Object
   Dim jo As JavaObject = Args(0)
   jo.RunMethod("next", Null)
   Dim removed As List = jo.RunMethod("getRemoved", Null)
   If removed.Size > 0 Then
     Dim tp As TabPage = removed.Get(0)
     Log($"Tab: ${tp.Text} removed."$)
   End If
   
   Return Null
End Sub

Sub addNewTab_MouseClicked (EventData As MouseEvent)
   tabCount=tabCount+1
   TabPane1.LoadLayout("tabLayout","Tab : "&tabCount)
End Sub
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
You'd have to test if removed list size is >0 on TabsListChanged_Event
B4X:
 Dim removed As List = jo.RunMethod("getRemoved", Null)
    If removed.Size>0 Then
          Dim tp As TabPage = removed.Get(0)
           Log($"Tab: ${tp.Text} removed."$)
        Return Null
    Else
    End If

P.D: One question thought it's why this sub is fired several times when closing a tab (more times related to Tab position)
 
Upvote 0
Top