Text in the Tab Panel
This tutorial introduces the tab panel and shows you how to populate the display area with text information.
The tab panel is versatile and can be configured for navigation around cards and stacks or simply to display information in the panel itself. This tutorial demonstrates how to create four tabs and populate the panel with the names of people who fall into a category that can be selected from the tabs.
Open LiveCode and select New stack from the File menu. This creates a new stack window on which to create the tab panel. Drag and drop a tab panel onto the card of the stack (1), then right click on the tab panel and select the Property Inspector (2). Make sure that you have selected the Basic Properties from the Property Inspector tabs. In order to display content on the tab panel ensure that Show name is ticked (3). Then update the content of the Tabs (One tab per line) field (4). You need to separate the names of each tab by returns. The default is "Tab 1" return "Tab 2" return "Tab 3". We are replacing this list with "Family" return "Friends" return "School Friends" return "Colleagues". Once you have made these change, close the Property Inspector. You may find that the tab panel window is not wide enough to fit the content from all four tabs. Widen the window by dragging and dropping the small rectangle boxes at the sides. You should be able to fit all four tabs into the LiveCode stack window without having to resize that.
Once you have updated the graphical layout and names of the tabs, you can write the code that displays the information in the panels. Right click on the tab panel you created and select Edit Script, to open the code editor. We are using a case construct to switch between the different tabs. Notice how the names of the tabs are reflected in the case statements. Each case statement is ended by a break statement. The code in each case statement produces a return delimited list of names that is to be displayed. You can update and alter the lists in order to experiment with the functionality. Add this code to the code editor:
on menuPick pItemName switch pItemName case "Family" set the label of me to "Mum" & return & "Dad" break case "Friends" set the label of me to "Scott Barnett" & return & "Nic O'Goramn" & \ return & "Fred Small" & return & "Michael Ralph" & return & \ "Sylvia Brown" & return & "Steve Smith" & return & \ "Morgan McDonald" break case "School Friends" set the label of me to "Claus Knorr" & return & "Gunnar Diem" break case "Colleagues" set the label of me to "Ben" & return & "Michael" & return & "Steve" & \ return & "Sharron" & return & "Jean" break end switch end menuPick
Don't forget to click Apply.
Switch to Run mode, and try out your tab panel. You should see it switch between the different lists of people entered in the code.
If you like this tutorial and would like to find out more about using the tab buttons, then you can read more about how to use the tab panel in the lesson: Using Tab Buttons.