B4J Question How to set the position of a splitpane diver?

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

would like to set the position of the divider of a splitpane (horizontal flow)?

Any hint on how to do so. Probably using JavaObject with RunMethod?

Appreciated,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private split1 As Node
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   SetDivider(split1, 0, 0.9)
End Sub

Sub SetDivider(Split As Node, DividerIndex As Int, Position As Double)
   Dim jo As JavaObject = Split
   jo.RunMethod("setDividerPosition", Array As Object(DividerIndex, Position))
End Sub
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Great ... have extended to below. It is amaizing what can be done with the JavaObject.
B4X:
' Sets the position of the divider for a splitpane
' Parameter: SplitPane, Index of the Divider, Position range 0 to 1
Sub setDividerPosition(Split As Node, DividerIndex As Int, Position As Double)
  Dim jo As JavaObject = Split
  jo.RunMethod("setDividerPosition", Array As Object(DividerIndex, Position))
  ' Log("setDividerPosition: Index: " & DividerIndex & ", Position: " & Position)
End Sub

' Gets the position of the divider for a splitpane
' Parameter: SplitPane, Index of the Divider
' Return: Position of the Divider range 0 to 1
Sub getDividerPosition(Split As Node, DividerIndex As Int) As Double
  Dim jo As JavaObject = Split
  Dim dp() As Double
  dp = jo.RunMethod("getDividerPositions", Null)
  If (DividerIndex < 0) OR (DividerIndex > dp.Length) Then Return -1
  ' Log("getDividerPosition: Index: " & DividerIndex & ", Position: " & dp(DividerIndex))
  Return dp(DividerIndex)
End Sub
Many Thanks.
 
Upvote 0
Top