B4J Question TabClosingPolicy

madru

Active Member
Licensed User
Longtime User
Good Morning,

is it possible to remove the close button (X) from a specific Tab?

regarding the Doc it is not possible isn't it?

public static enum TabPane.TabClosingPolicy
extends java.lang.Enum<TabPane.TabClosingPolicy>
This specifies how the TabPane handles tab closing from an end-users perspective. The options are:

  • TabClosingPolicy.UNAVAILABLE: Tabs can not be closed by the user
  • TabClosingPolicy.SELECTED_TAB: Only the currently selected tab will have the option to be closed, with a graphic next to the tab text being shown. The graphic will disappear when a tab is no longer selected.
  • TabClosingPolicy.ALL_TABS: All tabs will have the option to be closed.

[SOLVED]
 
Last edited:

madru

Active Member
Licensed User
Longtime User
Hi,

I was not really able to remove the X from Tab, instead of that I consumed the close event.

B4X:
Sub OnCloseRequest_Event (MethodName As String, Args() As Object) As Object

    Dim e As Event = Args(0)
    Dim jo As JavaObject = e
    Dim page As TabPage = jo.RunMethod("getSource", Null)
    'consume the event to prevent it from closing
    For a = 0 To ListView1.Items.Size - 1
        Private obj As Pane = ListView1.Items.Get(a)
        For Each n As Node In obj
            If n Is Pane Then
                Private pan As Pane
                pan = n
                For Each m As Label In pan
                    If m Is Label Then
                        Private lbl As Label
                        lbl = m
                        If page.Text = lbl.text Then
                            e.Consume
                        End If
                    End If
                Next
            End If
        Next
    Next

    If page.Text = "my_always_not_closing_tab" Then
        e.Consume
    End If

    Return Null

End Sub
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
This works:
B4X:
setTabClosingPolicy(tab1, "UNAVAILABLE") '"ALL_TABS", "SELECTED_TAB"

Public Sub setTabClosingPolicy(Obj As Object, value As String)
    Dim jo As JavaObject = Obj
    jo.RunMethod("setTabClosingPolicy", Array As Object(value))
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi jmon,

not sure I understand, setTabClosingPolicy will work for a TabPane but not for a single Tab or have I missed something?
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
for a single Tab
Ok then in this case that would be a combinason of the previous post (for the tabPane) and this for your tab page:

B4X:
setTabClosable(myPage, False)

Public Sub setTabClosable(Obj As Object, value As Boolean)
    Dim jo As JavaObject = Obj
    jo.RunMethod("setClosable", Array As Object(value))
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…