B4J Question Set Splitter Bar Minimum and Maximum Position in a Form

BPak

Active Member
Licensed User
Longtime User
I have a Split Pane (Vertical) in a window and want to be able to set its Minimum and Maximum position.

If a user were to move it too high up in the Form then the event could set the Split bar position to minimum allowed.

Can not find an event to do this. Is it possible using JavaObject?
 

Attachments

  • SpliBarPos.zip
    1.2 KB · Views: 339

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

found a way as shown below using the top anchorpane height. May be there are easier solutions as well ;)

B4X:
' Top Anchorpane Height used to set min / max position of the splitpane divider
Sub apTop_Resize (Width As Double, Height As Double)
    Dim MinDividerPos As Double = 0.25
    Dim MaxDividerPos As Double = 0.75
    Dim dp As Double = getDividerPosition(split1, 0)
    If dp <= MinDividerPos Then setDividerPosition(split1, 0, MinDividerPos)
    If dp >= MaxDividerPos Then setDividerPosition(split1, 0, MaxDividerPos)
End Sub

'
' SECTION: SPLITPANE DIVIDER
' See http://docs.oracle.com/javafx/2/api/javafx/scene/control/SplitPane.html#getDividerPositions()
'

' Sets the position of the divider for a splitpane
' Parameter SplitPane: The SplitPane
' Parameter Index: The index of the Divider. Starting with 0
' Parameter Position: The position of the divider to be between 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))
End Sub

' Gets the position of the divider for a splitpane
' Parameter Split: The SplitPane
' Parameter Index: 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
  Return dp(DividerIndex)
End Sub
 
Upvote 0

BPak

Active Member
Licensed User
Longtime User
I will try that method. Use the Pane height resize event. Thanks for the help!!

EDIT:

I found a very easy way to do this without any code.

In Scene Builder for a Vertical Split Pane go to the LAYOUT section and set the Min Height to the minimum height you want the panel to go to. Do this for both of the Anchor Panes of the Splitter.

For the Horizontal Splitter use the Min Width setting in the Layout section.

No flicker - just clean scrolling in the Form.
 
Last edited:
Upvote 0
Top