Tab Panes

Overview

Many programs have more to show than fits on one screen. A web browser holds many pages, and a settings window holds many groups of options. A tab pane solves this by letting several panels share the same space. A row of tabs sits along the top, and only the panel for the chosen tab is shown. In this tutorial, you will put a tab pane on a form, put content in each tab, add new tabs while the program runs, and find out when a tab is opened or closed. You will also learn which keys a keyboard or screen reader user presses to move between tabs.

Goals

You have the following goals for this tutorial:

By the end of this lesson, you can

  • Put a TabPane on a form page and fill it with Tab objects that each show their own content
  • Give each tab a name and description so that a screen reader can read it
  • Add tabs while a program is running, using a button and a behavior
  • Use a TabChangeListener to find out when a tab is opened or closed

Warm up

Think of a program you use that has tabs, like a web browser, a spreadsheet or a settings window. Why did its designers use tabs instead of putting everything on one long page? What would go wrong if the program had 40 tabs? How do you think a person who uses only a keyboard moves from one tab to the next?

Vocabulary

You will be learning about the following vocabulary words:

Vocabulary
TermDefinition
Tab paneA control that holds several panels in the same space and shows one of them at a time.
TabA labeled button in a tab pane's tab bar. Choosing a tab shows the panel that belongs to it.
Tab barThe row of tabs along the top of a tab pane.
Related itemThe content that a tab shows when it is chosen. It can be a single item or a panel holding many controls.
ListenerAn object that a program asks to be told when something happens. A TabChangeListener is told when a tab opens or closes.

New Code to Learn

You will be using the following new pieces of code:

New Code to Learn
Quorum CodeCode ExampleExplanation
TabPaneTabPane paneCreates a new tab pane with no tabs in it.
TabTab tabCreates a new tab. It has no name and no content until you set them.
SetRelatedItem(Item2D item)tab:SetRelatedItem(label)Sets the content that the tab shows when it is chosen.
Add(Tab tab)pane:Add(tab)Adds a tab to the end of the tab pane's tab bar.
page:Add(item)page:Add(pane)Puts a control that has no Add action of its own on a form page.
SetPixelHeight(number height)pane:SetPixelHeight(300)Sets a height in pixels.
DisplayCloseButton(boolean display)notesTab:DisplayCloseButton(false)Shows or hides a tab's close button.
Select(Tab tab)pane:Select(tab)Chooses a tab. Its content is shown and the focus moves to it.
GetSelectedTab()Tab current = pane:GetSelectedTab()Returns the tab that is chosen right now.
AddTabChangeListener(TabChangeListener listener)pane:AddTabChangeListener(listener)Asks the tab pane to tell a listener whenever a tab is opened or closed.

CSTA Standards

This tutorial covers the following 2026 CSTA standards:

For teachers · 2026 CSTA K–12 Computer Science Standards

HS-PRO-TR-19

High School · Programming

Evaluate a computing technology's alignment with design specifications and responsible design values, including its correctness, effectiveness, and user experience.

Also in 7 other lessons

MS-PRO-TR-20

Middle School · Programming

Refine a computing technology based on user feedback to improve its usability and accessibility.

Also in 7 other lessons

S1-SWD-UX-04

Specialty I · Software Development

Refine a user interface design using accessibility and responsive design tools.

Also in 13 other lessons

MS-SYS-IM-36

Middle School · Systems & Security

Collaborate to improve the design of a computing system to meet the needs of diverse users.

Also in 1 other lesson

Every standard, and the lessons that cover it

Explore

Tabs and tab panes

A tab pane has two parts. Across the top is the tab bar, a row of tabs. Below it is the view area, where the content of the chosen tab is shown. Each tab has a name, which is the text on the tab, and a related item, which is the content it shows. Only one tab is chosen at a time. The other tabs keep their content; it is just not drawn until you choose them again.

Each tab also has a small close button. From the keyboard, Ctrl+F4 (Command+W on a Mac or in a web browser) closes the chosen tab instead. Closing a tab removes it from the tab pane.

Putting a tab pane on a form

A page has actions like AddButton for many controls, but there is no AddTabPane. For a control like this, you make it yourself and put it on the page with page:Add. The page gives it its own row.

The program below makes a study planner with three tabs. Each tab's content is a label with a reminder. The MakeTab action builds one tab, so the same code is not written three times.

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.TabPane
use Libraries.Interface.Controls.Tab
use Libraries.Game.Graphics.Label

class Main
    action Main
        Form form
        Page page = form:GetMainPage()
        page:SetTitle("Study Planner")

        TabPane pane
        pane:SetName("Subjects")
        pane:SetDescription("One tab for each subject")
        pane:SetPercentageWidth(0.8)
        pane:SetPercentageHeight(0)
        pane:SetPixelHeight(300)

        pane:Add(MakeTab("Math", "Finish the practice problems."))
        pane:Add(MakeTab("Science", "Read the chapter on plants."))
        pane:Add(MakeTab("History", "Pick a topic for the project."))

        page:Add(pane)
        form:Display()
    end

    action MakeTab(text name, text reminder) returns Tab
        Label label
        label:SetText(reminder)
        label:SetFocusable(true)

        Tab tab
        tab:SetName(name)
        tab:SetDescription("Reminders for " + name)
        tab:SetRelatedItem(label)
        return tab
    end
end

A few things to notice:

  • The size. A tab pane starts out as wide and as tall as whatever holds it. On a page, that is too tall, so the program sets its own size: SetPercentageWidth(0.8) makes it 80% as wide as the page, like the page's other rows. SetPercentageHeight(0) turns off the "as tall as the page" part, and SetPixelHeight(300) makes it 300 pixels tall.
  • The content. tab:SetRelatedItem(label) connects a tab to its content. You never place the label yourself; the tab pane puts it in the view area when its tab is chosen.
  • Every tab's content can take the focus. When a tab is chosen, the focus moves to the first thing in its content that can take the focus, and a screen reader reads it. label:SetFocusable(true) makes the label such a thing. Every tab's content must have at least one item that can take the focus.
  • The focus starts in the tab pane. When the form opens, it gives the focus to the first thing on the page that can take it. Here that is the page's title. Press Tab to move into the tab pane. When a tab pane gets the focus and no tab is chosen yet, it chooses the first tab and moves the focus into its content.

You can also add many tabs at once. An array is a group of values kept in order, so an Array<Tab> is a group of tabs. If you have one, then pane:Add(tabs) adds every tab in the array, in order. The Arrays tutorial shows how to make one.

Using a tab pane with the keyboard

Every tab pane in Quorum works with the keyboard. These keys work when the focus is anywhere inside the tab pane, on a tab or in its content:

A tab pane's keys
What it doesWindows and LinuxMac and web browser
Choose the next tabCtrl+TabCtrl+]
Choose the previous tabCtrl+Shift+TabCtrl+[
Close the chosen tabCtrl+F4Cmd+W
Leave the content and go back to the tabsEscEsc

When the focus is on a tab, Tab and Shift+Tab move to the next or previous tab, going around in a loop. Space or Enter chooses the tab and moves the focus into its content. A screen reader reads the tab's name, says that it is a tab, and reads its description. This is why every tab should have a short, clear name: the name is all that many users notice before they choose.

Because Tab goes around the tabs in a loop, it doesn't move on to the rest of the page. So put the tab pane last on its page, and put the other controls the page needs inside its tabs.

Adding tabs while the program runs

A tab pane can change while the program runs. Next, you will add a button that makes a new tab each time it is pressed. A button runs a behavior when it is pressed, so make a new class named AddTabBehavior:

use Libraries.Game.Graphics.Label
use Libraries.Interface.Behaviors.Behavior
use Libraries.Interface.Controls.Tab
use Libraries.Interface.Controls.TabPane
use Libraries.Interface.Events.BehaviorEvent

class AddTabBehavior is Behavior
    TabPane pane = undefined
    integer count = 0

    action Run(BehaviorEvent event)
        if pane = undefined
            return now
        end

        count = count + 1

        Label label
        label:SetText("This is note number " + count + ".")
        label:SetFocusable(true)

        Tab tab
        tab:SetName("Note " + count)
        tab:SetDescription("A note made while the program was running")
        tab:SetRelatedItem(label)

        pane:Add(tab)
        pane:Select(tab)
    end

    action SetTabPane(TabPane newPane)
        pane = newPane
    end
end

The behavior needs to know which tab pane to add to, so SetTabPane stores it. pane:Select(tab) chooses the new tab and moves the focus into its content, so a screen reader reads the new note right away. Press Esc to go back to the tabs.

Listening for tabs that open and close

A listener is an object that a program asks to be told when something happens. A TabChangeListener is told when a tab is added to a tab pane (OpenedTab) and when one is closed (ClosedTab). Each time, it gets a TabChangeEvent, and GetTab returns the tab that changed. Make a class named TabLogger:

use Libraries.Interface.Events.TabChangeEvent
use Libraries.Interface.Events.TabChangeListener

class TabLogger is TabChangeListener
    action OpenedTab(TabChangeEvent event)
        output "Opened the tab " + event:GetTab():GetName()
    end

    action ClosedTab(TabChangeEvent event)
        output "Closed the tab " + event:GetTab():GetName()
    end
end

The finished program

Where should the button go? The tab pane is last on the page, so the button goes inside a tab. The finished program adds a first tab named Notes whose content is the button. DisplayCloseButton(false) hides the Notes tab's close button, so the button can't be closed away by accident.

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.TabPane
use Libraries.Interface.Controls.Tab
use Libraries.Interface.Controls.Button
use Libraries.Game.Graphics.Label

class Main
    action Main
        Form form
        Page page = form:GetMainPage()
        page:SetTitle("Study Planner")

        TabPane pane
        pane:SetName("Subjects")
        pane:SetDescription("A Notes tab and one tab for each subject")
        pane:SetPercentageWidth(0.8)
        pane:SetPercentageHeight(0)
        pane:SetPixelHeight(300)

        TabLogger logger
        pane:AddTabChangeListener(logger)

        AddTabBehavior addBehavior
        addBehavior:SetTabPane(pane)

        Button addButton
        addButton:SetName("Add a note tab")
        addButton:SetDescription("Adds a new tab to the end of the tab pane")
        addButton:SetBehavior(addBehavior)

        Tab notesTab
        notesTab:SetName("Notes")
        notesTab:SetDescription("Add new note tabs here")
        notesTab:SetRelatedItem(addButton)
        notesTab:DisplayCloseButton(false)
        pane:Add(notesTab)

        pane:Add(MakeTab("Math", "Finish the practice problems."))
        pane:Add(MakeTab("Science", "Read the chapter on plants."))
        pane:Add(MakeTab("History", "Pick a topic for the project."))

        page:Add(pane)
        form:Display()
    end

    action MakeTab(text name, text reminder) returns Tab
        Label label
        label:SetText(reminder)
        label:SetFocusable(true)

        Tab tab
        tab:SetName(name)
        tab:SetDescription("Reminders for " + name)
        tab:SetRelatedItem(label)
        return tab
    end
end

Run the program and press Tab. The Notes tab is chosen and the focus is on the button. Press it a few times, then close a note tab with its close button or the keyboard. Each change is written to the output by TabLogger.

Blocks

Finding the chosen tab

To find out which tab is chosen, use GetSelectedTab. It returns undefined if no tab is chosen, so check before you use it:

Tab current = pane:GetSelectedTab()
if current not= undefined
    output "The chosen tab is " + current:GetName()
end

Engage

In this activity, you and a partner build a small "class information" program with a tab pane on a form, and check that every tab and control can be reached with and without a mouse. The goal is to organize information into tabs, and to understand how focus moves between the tabs and what's inside them. Start by planning three or four tabs together, such as Schedule, Homework and Contacts, and decide what each one shows. Then build the tab pane, with a name and a description on every tab, and make sure each tab's content can take the focus. Put a button inside one tab. Press Esc from that button and check that the focus goes back to the tabs. When it works, trade programs with your partner.

Wrap up

Tabs save space, but they also hide things. When is a tab pane a good choice, and when would a single page, or a menu, be better? Think about what a user can no longer find when a tab is not chosen.

In the next tutorial, Menus, you will give a program a menu bar.