### Add TabPages to TabPane

Example adding a TabPage to a TabPane.
Define the Main Layout using the B4J Visual Designer
For this example, the layout contains a view called tpMain.
Set properties accordingly, like Tabs Side and set the horizontal & vertical anchors to both.
Add the View tpMain to the B4J Project File via Tools > Generate Members.
Define the TabPage Layout using the B4J Visual Designer
Recommend to use a pane, which horizontal & vertical anchors are set to both.
In the pane add the views required.
Generate the Views via Tools > Generate Members.
B4J Code
Variables
`Sub Process_Globals
'Generated via the B4J Visual Designer
Private tpMain As TabPane
'Add new TabPage
Private tp1 As TabPage
...
End Sub`
AppStart
`Sub AppStart (Form1 As Form, Args() As String)
'Add the main layout
MainForm.RootPane.LoadLayout("Main")
...
'Add the TabPage
tp1 = AddTabPage("Tab A", 1)
Option 1 Subroutine AddTabPage
Example of a subroutine to add a TabPage:
'Add a tabpage with external layout.
'Example Dim tp1 As TabPage = AddTabPage("Tab A", "A","TabPage")
`Sub AddTabPage(tabtext As String, id As String, layout As String) As TabPage
Dim tabpageNew As TabPage
tabpageNew.Initialize
tabpageNew.Id = id
tabpageNew.Text = tabtext
'Load the TabPage layout into an anchorpane. The layout uses a pane with anchors set.
Dim ap As AnchorPane
ap.Initialize("")
ap.LoadLayout(layout)
tabpageNew.Content = ap
tpMain.Tabs.Add(tabpageNew)
Return tabpageNew
End Sub`
Option 2 Adding a TabPage using a Button
Private btnTabAdd As Button
`Sub btnTabAdd_Action
Log("Adding a New Tab")
Dim tabpageNew As TabPage
tabpageNew.Initialize
tabpageNew.Id = "tabpage" & (tpMain.Tabs.Size + 1)
tabpageNew.Text = "Tab " & (tpMain.Tabs.Size + 1)
'Set the background color of the anchorpane of the new tab
Dim ap As AnchorPane
ap.Initialize("")
tabpageNew.Content = ap
ap.Style = "-fx-background-color: red;"
addSpinner(ap)
'
tpMain.Tabs.Add(tabpageNew)
End Sub`
`

Changed: 2018-04-15 16:54, Category: TabPage and TabPane, File: T6C260M1909.htm, ID: 1909