B4J Question Move TabPane - dragged and drop

Lego Jérôme

Member
Licensed User
Hi,

i try to drag and drop my tabpage, to change the order of this tabpage.
I managed to do this code but it's not really the good way for do that.

B4X:
Sub TabPaneMatiere_MouseDragged (EventData As MouseEvent)
    moveTabPane(EventData.X,TabPaneMatiere)  
End Sub


Sub moveTabPane(posX As Double,tabPane As TabPane)  
    Dim n As Int = tabPane.SelectedIndex
    Dim valeur As Int = 75
   
    Dim t As TabPage = tabPane.Tabs.Get(n)
   
   
    If posX>num+valeur Then
        If n<tabPane.Tabs.Size-1 Then
            tabPane.Tabs.RemoveAt(n)
            tabPane.Tabs.InsertAt(n+1,t)
            tabPane.SelectedIndex=n+1
            num = posX
            Log("droite")
        End If
    Else
        If posX<num-valeur Then
            If n>0 Then
                tabPane.Tabs.RemoveAt(n)
                tabPane.Tabs.InsertAt(n-1,t)
                tabPane.SelectedIndex=n-1
                num = posX
                Log("gauche")
            End If
        End If
    End If
End Sub

what I would like to do is that if we hold the element farther than the next half then it is moved to the index
with my solution I can move the tabpane but it's not clean

Someone would have an idea to realize its more neatly ?
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
If you are using Java 11 and the new B4J IDE then it is a simple two line code addition to allow the tabs to be reordered by dragging.
(This will only work on Java 10 and above)
B4X:
Dim jo As JavaObject = yourTabPane
jo.RunMethod("setTabDragPolicy",Array("REORDER"))
 
Last edited:
Upvote 0
Top