B4J Question Add more titledpanes to accordion

jmon

Well-Known Member
Licensed User
Longtime User
Try this:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private accordion As Node
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
     
    'New Titled Pane:
    Dim NewTitledPane As JavaObject
    NewTitledPane.InitializeNewInstance("javafx.scene.control.TitledPane", Array("(New TitledPane) : Title", Null))

    'Let's add a button to the new titledpane:
    Dim btn As Button
    btn.Initialize("")
    btn.Text = "New button"
    '-> add the button to the titledpane:
    NewTitledPane.RunMethod("setContent", Array(btn)) 

    'Get the content of the accordion:
    Dim AccordionItems As List
    AccordionItems = AsJo(accordion).RunMethod("getPanes", Null) 
    'Add the titledpane to the accordion:
    AccordionItems.Add(NewTitledPane)
 
    'Set new titled pane expanded:
    NewTitledPane.RunMethod("setExpanded", Array(True))
 
End Sub

'This function is used to convert a node to a javaobject:
Sub AsJo(o As JavaObject) As JavaObject
    Return o
End Sub

Here I add a titledpane to the accordion, then a button to the titledpane, then expand the new titled pane.
 
Upvote 0
Top