Text in the Tab Panel

This tutorial introduces the tab panel and shows you how to populate the display area with text information.

Introduction

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.

Creating Tabbed Buttons

Open LiveCode and select New Mainstack 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 drop down list of the Property Inspector. In order to display content on the tab panel ensure that Display 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.

The Code

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. The script editor appears and populates the editor with four lines of code that provide you with a basic framework into which to add the functionality you want to implement. 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.

on menuPick pItemName
    switch pItemName
        case "Family"
            set the label of me to " "
            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

Putting it Together

The image in this step shows you the tab panel in operation and the code that is used to provide the information that is displayed.

Further Reading

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.

Comments (5)

Tom Bodine Monday Sep 02 at 01:57 PM

Nice tutorial! But if you want to create or change a tabbed menu at runtime, you need another way.

You can do that by first getting the return delimited list of your button's current tabs with this line:

put the text of button "myTabs" into ttabs

Modify ttabs to change your tabs, then update the button with this line:

set the text of button "myTabs" to ttabs

franco Monday Apr 21 at 12:32 PM

hi there,
how can I close a substack and go back to the main stack?
and how can I close all (when in run mode)?

thanks for your attention
franco

Michel Bujardet Saturday Apr 26 at 11:24 PM

For some reason, nothing displays in the tabbed menu label. Neither at design or at run time. I copied the code and verified it. Nothing :(

Alejandro Tejada Sunday Apr 27 at 11:40 AM

Hi Michel,

Notice this important step:

Make sure that you have selected the Basic Properties from the drop down list of the Property Inspector. In order to display content on the tab panel ensure that "Display name" is ticked...

Sometimes instead of "Display Name" appears "showName".
Just tick the checkbox and each tab displays all names correctly.

Elanor Buchanan Thursday May 08 at 04:15 AM

Hi Franco

You can do this is script using the close command, e.g.

close stack "mySubstack"

The close command closes the stack window immediately, but it does not necessarily remove the stack from memory. A stack that is closed but in memory still takes up space in RAM and its objects are still accessible to scripts.

If you want to explicityly navigate to another stack you can use the go command.

I hope that helps.

Kind regards

Elanor

Add your comment

E-Mail me when someone replies to this comment