B4J Question SplitPane

tomazc

Member
Licensed User
Longtime User
Is it possible to create SplitPane with sections runtime, without using designer. I want to create two sections and add some controls on each section.

I will be grateful if you can send me this information or an example.

Regards, Tomaz
 

jmon

Well-Known Member
Licensed User
Longtime User
Hi, you can do it this way:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private SplitPane As JavaObject
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    MainForm.Show
  
    SplitPane.InitializeNewInstance("javafx.scene.control.SplitPane", Null)
    MainForm.RootPane.AddNode(SplitPane, 0, 0, -1, -1)
    MainForm.RootPane.SetAnchors(SplitPane, 10, 10, 10, 10)
  
    'Adding 3 panes to the splitpane  
    Dim ap1 As AnchorPane
    ap1.Initialize("")
    ap1.Style = $"-fx-background-color:blue;"$

    Dim ap2 As AnchorPane
    ap2.Initialize("")
    ap2.Style = $"-fx-background-color:white;"$

    Dim ap3 As AnchorPane
    ap3.Initialize("")
    ap3.Style = $"-fx-background-color:red;"$
  
    Dim SplitPaneItems As List = SplitPane.RunMethod("getItems", Null)
    SplitPaneItems.AddAll(Array(ap1, ap2, ap3))  

    SplitPane.RunMethod("setDividerPositions", Array(Array As Double(0.33, 0.66)))
'    SplitPane.RunMethod("setOrientation", Array("VERTICAL"))
      
End Sub

Then just add some controls to the anchorPanes.
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
A second possibility will be to use 2 different layouts, one with and the other without splitpane...and load them when needed:
B4X:
   Sub Button1_Action
    MainForm.RootPane.RemoveAllNodes
    MainForm.RootPane.LoadLayout("2") 'Load the layout file 2 with splitpane.
End Sub
 
Upvote 0
Top