B4J Code Snippet SplitPane PositionChanged_Event

My splitpane contains a customlistview with textareas which have to measure height baesd on text length. So I have to turn off the handle resize event in layout designer.

To add a SplitPane PositionChanged_Event, we can first get its dividers and then add a change listener to its positionProperty.

Sub init
    Dim jo As JavaObject
End Sub

Sub addPositionChangedEvent(divider As Object,eventName As String)
    Dim Obj As Reflector
    Obj.Target = divider
    Obj.AddChangeListener(eventName, "positionProperty")
End Sub

Sub dividerPosition_changed(old As Object, new As Object)
End Sub


Active Member
Licensed User
FYI a few notes from when I added this to an application. [updated]
I found a ScrollPane to be sluggish in updating to a divider move and sometimes appeared to miss adjusting its width, and sometimes it might update to an older divider-width if I tried to set it in AdjustViewComponentsToDividers w/o a delay. The ScrollPane contained a WebView.
So I used a delay, 250 was good enough, 5 was too small, but also found I needed to force the ScrollPane to the correct size, or it would be 'off'.

Easiest way to get the ScrollPane to be 'off' was to double-click the application Window (to switch to maximized or to 'restored' size) and it would always be 'off' in size. Grab the divider and move it a bit and then it was close but not always on. With this code, whether maximizing/restoring or moving the divider, it always looked correct (afterthe fraction of a second).

    ' example 4 areas with 3 dividers        ' in code setting up the SplitPane
    Dim dpos() As Double = Array As Double(0.1,0.4,0.9)
    SplitPane1.DividerPositions = dpos

Sub dividerPosition_changed(old As Object, new As Object)
End Sub

Sub AdjustViewComponentsToDividers
    'adjust something in the 2nd split
    [adjust something's].Width = (SplitPane1.DividerPositions(1)-SplitPane1.DividerPositions(0))*SplitPane1.Width
End Sub
Last edited: