B4J Question [solved] TabPane-Page per Code?

Knoppi

Active Member
Licensed User
Longtime User
Is it possible to create a TabPane-Page per Code without LoadLayout?
 
Last edited:

Knoppi

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0

Knoppi

Active Member
Licensed User
Longtime User
this works
B4X:
Dim TabPanel1 As TabPane
TabPanel1.Initialize("")
MainForm.RootPane.AddNode( TabPanel1, 0,0,500,500)

Dim tp As TabPage
tp.Initialize
tp.Text = "Page1"

TabPanel1.Tabs.Add( tp)
but when i try to add a label i get an error
B4X:
Dim lbl As Label
lbl.Initialize("")
lbl.Text = "Label1"

tp.Content.AddNode( lbl, 0, 0, 100, 20)  ' throws error
Program started.
Error occurred on line: 28 (Main)
java.lang.RuntimeException: Object should first be initialized (Pane).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4j.objects.PaneWrapper.getNumberOfNodes(PaneWrapper.java:315)
at anywheresoftware.b4j.objects.PaneWrapper.AddNode(PaneWrapper.java:257)
at b4j.example.main._appstart(main.java:117)
...
which object Pane I must initialize
i try this, but same error
tp.Content.Initialize("")

my solution:
B4X:
Dim p As Pane
p.Initialize("")
tp.Content = p
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
This works, to add a TabPane I simply load an empty layout:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
  
    TabPanel1.Initialize("")
    MainForm.RootPane.AddNode( TabPanel1, 0,0,500,500)
    TabPanel1.LoadLayout("TabPaneEmpty", "Test 1")
    TabPanel1.LoadLayout("TabPaneEmpty", "Test 2")
    TabPanel1.LoadLayout("TabPaneEmpty", "Test 3")
  
    Private lblTest1 As Label
    lblTest1.Initialize("")
    Private tp As TabPage
    tp = TabPanel1.Tabs.Get(0)
    tp.Content.AddNode(lblTest1, 20, 20, 200, 40)
    lblTest1.Text = "Pane 1"
  
    Private lblTest2 As Label
    lblTest2.Initialize("")
    Private tp As TabPage
    tp = TabPanel1.Tabs.Get(1)
    tp.Content.AddNode(lblTest2, 20, 20, 200, 40)
    lblTest2.Text = "Pane 2"
End Sub
Attached my test project.
 

Attachments

  • TabPaneInCode.zip
    1.7 KB · Views: 201
Upvote 0
Top