B4J Question [SOLVED] Closable and Non-closable tag pages with layouts

mfstuart

Active Member
Licensed User
Longtime User
Hi all,
I'm trying to build a B4J desktop app that will have a tabpane with user added tabpages.
When the app starts it will have a default "Home" tabpage which will not be closable.
Any tabpage added by a user from clicking a "menu" option from a ListView, will be able to be closed by the user - it will have an x button on the tab.
The trouble is I can get this user interface to work, but I can't get the "Home" page to load a layout, but with all other pages, I can load a layout to it.

I've attached an example B4J app to show what I'm trying to do. and I explain more in the app about this issue.

Can someone look at this and see what I need to do to get a layout associated to the Home page and the tab to not be closed by the user - no x button?

Thanx,
Mark Stuart
 

Attachments

  • TabPane_Page.zip
    31.9 KB · Views: 340

Daestrum

Expert
Licensed User
Longtime User
Just use
B4X:
pane.LoadLayout(LayoutName,tabname)

to load the tabs
and this after you have loaded the home tab (which I assume to be the first tab)

B4X:
Dim jo as JavaObject = TabPane1.Tabs.Get(0)
jo.RunMethod("setClosable",Array(False))

I think where you execute this code (below) for each added tab it overwrites the setting for the 'Home' tab
Executing it once will set it for all tabs (as far as I can determine) it can be executed even before you add any tabs.
B4X:
 Dim jo As JavaObject = pane
 jo.RunMethod("setTabClosingPolicy", Array("ALL_TABS"))

Tiny example attached
 

Attachments

  • tabclosing.zip
    4.2 KB · Views: 323
Last edited:
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Hi Daestrum,
Thanx for giving me a solution to the issue.
I did make a small change to your sample, where I moved the call to make the closable on the "Home" page before loading the other tabs and layouts, as it simulates the user adding (eg: by clicking a button) the other tabs in the order that it may happen.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("lay1") 'Load the layout file.
    MainForm.Show
    asJO(TabPane1).RunMethod("setTabClosingPolicy", Array("ALL_TABS"))
    TabPane1.LoadLayout("lay2","Home")
    asJO(TabPane1.Tabs.Get(0)).RunMethod("setClosable",Array(False))
   
    TabPane1.LoadLayout("lay3","User")
    TabPane1.LoadLayout("lay2","Extra")
    TabPane1.LoadLayout("lay3","Extra2")
    'asJO(TabPane1.Tabs.Get(0)).RunMethod("setClosable",Array(False))
End Sub

Thanx,
Mark Stuart
 
Upvote 0
Top