Text Boxes
Overview
A text box is an area where a person can type many lines of text, like notes, a story or a program. Quorum Studio's code editor is built on the same idea. In this tutorial, you will put two text boxes on a page, add buttons that clear, show and copy text between them, and then add line numbers and colored, underlined text.
Goals
You have the following goals for this tutorial:
By the end of this lesson, you can
- Add text boxes to a page and give each one a clear label, name and description
- Get, set, add to and empty the text in a text box from code
- Use a
TextBoxSelectionto work with the text a person has selected - Add a line number gutter and a text style, and explain why style alone shouldn't carry meaning
- Examine how autocorrect, an algorithm in many text boxes, helps some people and harms others
- Evaluate how automation such as self-driving vehicles can create and replace jobs
Warm up
Think of three programs where you type more than one line of text: maybe a word processor, a chat app and a code editor. What extra features does each one add beyond typing? Which of those features would you miss most if they were gone?
Vocabulary
You will be learning about the following vocabulary words:
| Term | Definition |
|---|---|
| Text box | A control where a person types and edits many lines of text. |
| Selection | The part of the text a person has highlighted, with the mouse or with Shift and the arrow keys. |
| Index | The position of a character in the text, counting from 0. In "Hello world!" the w is at index 6. |
| Gutter | A strip down the left side of a text box, such as the line numbers in a code editor. |
| Text style | A change in how part of the text looks, such as its color or an underline. |
| Autocorrect | An algorithm in many text boxes that changes or marks words it thinks are misspelled. |
| Automation | Using technology to do work that people used to do by hand. |
New Code to Learn
You will be using the following new pieces of code:
| Quorum Code | Code Example | Explanation |
|---|---|---|
| AddTextBox(text name) | TextBox notes = page:AddTextBox("Notes") | Adds a text box to a page. The name is what a screen reader says for the text box. |
| GetTextBox(text name) | TextBox notes = page:GetTextBox("Notes") | Finds a text box on a page by its name. |
| SetLayoutRows(number rows) | notes:SetLayoutRows(8) | Sets how many lines tall the text box is on the page. |
| SetText(text value) | notes:SetText("Dear diary,") | Replaces all of the text in the text box. |
| GetText() | text all = notes:GetText() | Returns all of the text in the text box. |
| AppendToText(text value) | notes:AppendToText("More notes.") | Adds text to the end of the text box. |
| Empty() | notes:Empty() | Removes all of the text from the text box. |
| GetSelection() | TextBoxSelection selection = notes:GetSelection() | Returns the part of the text the person has selected. |
| GetLineCount() | integer lines = notes:GetLineCount() | Returns how many lines of text are in the text box. |
| Add(Gutter gutter) | notes:Add(cast(Gutter, gutter)) | Adds a gutter, such as a LineNumberGutter, to the text box. |
| AddTextStyle(text name, TextStyle style) | notes:AddTextStyle("important", style) | Changes how part of the text looks. |
CSTA Standards
This tutorial covers the following CSTA standards:
For teachers · 2026 CSTA K–12 Computer Science Standards
High School · Programming
Create a modular program that uses procedures, external libraries, or objects to improve reusability and readability.
Also in 9 other lessons
Middle School · Programming
Use a procedure to structure code for clarity and reusability.
Also in 5 other lessons
Middle School · Algorithms & Design
Examine evidence of beneficial and harmful impacts, ethical issues, and biases of algorithms encountered in daily life.
Only this lesson so far
Middle School · Computing & Society
Evaluate how automation in technology can create or replace jobs and change how people work.
Only this lesson so far
High School · Systems & Security
Investigate how computing systems and infrastructure impact society and the environment, identifying who is affected and why.
Only this lesson so far
High School · Computing & Society
Propose modifications to an existing policy or piece of legislation that encourages ethical innovation and minimizes societal risks associated with technology.
Only this lesson so far
Grade 4 · Computing & Society
Analyze how the limitations of existing technologies can lead to emerging technologies.
Only this lesson so far
Specialty I · Software Development
Refine a user interface design using accessibility and responsive design tools.
Also in 13 other lessons
Explore
Text boxes and text fields
In the Text Fields tutorial, you used a text
field for one line of text. A text box (TextBox) holds many lines. It
scrolls when the text doesn't fit, and it can show extras like line numbers.
Most of the actions are the same: GetText, SetText and Empty work just
as they do on a text field.
A person can type in a text box with the usual editing keys: the arrow keys, Home and End, Shift to select, Enter for a new line, and Ctrl+A, Ctrl+C, Ctrl+X, Ctrl+V, Ctrl+Z and Ctrl+Y (use Cmd on a Mac).
Making two text boxes
In this tutorial, we build a small note copier: a "Source notes" box and a "Copied notes" box. A page's AddTextBox action makes a text box and adds it
to the page. The page makes it as wide as the row and four lines tall. SetLayoutRows makes it taller.
Like a text field, a text box shows no words of its own, so each one gets a label. A label added right before a text box sits above it.
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.TextBox
Form form
Page page = form:GetMainPage()
page:SetTitle("Note Copier")
page:AddLabel("Source notes:")
TextBox source = page:AddTextBox("Source notes")
source:SetDescription("Type or paste text here, then select part of it to copy.")
source:SetText("Select some of this text, then press Copy selection.")
source:SetLayoutRows(6)
page:AddLabel("Copied notes:")
TextBox target = page:AddTextBox("Copied notes")
target:SetDescription("Text you copy from the source notes appears here.")
target:SetLayoutRows(6)
form:Display()
The two boxes have different names and descriptions, so a screen reader user can tell them apart. Don't rely on color or position alone to tell them apart: a person who can't see the screen, or who can't tell the colors apart, would miss it.
Moving the focus with Tab
The page sets the Tab order for you, top to bottom: the title, then each
label and the text box under it. In a text box, Tab moves the focus to the next control
by default. That's what you want in most programs, because it means a
keyboard user is never trapped in a text box. A code editor is different:
there, Tab should indent. You can switch with SetMoveFocusOnTab(false),
but then you must give keyboard users another way to leave the box.
Buttons that work with the text
Next, we add four buttons in a row under the text boxes. Each one gets its
own behavior class. Each behavior is a FormBehavior, so it can find the
text boxes on the page by their names with GetTextBox. This keeps every
class small and easy to read.
Clear empties the copied notes. Make ClearBehavior.quorum:
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Forms.Page
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.TextBox
class ClearBehavior is FormBehavior
action Run(BehaviorEvent event)
Page page = GetPage()
TextBox target = page:GetTextBox("Copied notes")
if target not= undefined
target:Empty()
end
end
end
Show text outputs the copied notes and counts their lines. Make ShowBehavior.quorum:
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Forms.Page
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.TextBox
class ShowBehavior is FormBehavior
action Run(BehaviorEvent event)
Page page = GetPage()
TextBox target = page:GetTextBox("Copied notes")
if target not= undefined
output target:GetText()
output "That is " + target:GetLineCount() + " lines."
end
end
end
Working with the selection
When a person selects text, the text box keeps track of where the selection starts and ends. Each position is an index: the number of characters before it, counting from 0. If the text is "Hello world!" and "world" is selected, the selection starts at index 6 and ends at index 11.
GetSelection returns a TextBoxSelection with these indexes. Its IsEmpty
action is true if nothing is selected, and its GetText action returns the
selected text. Copy selection adds the selected text to the end of the
copied notes. Make CopySelectionBehavior.quorum:
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Forms.Page
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.TextBox
use Libraries.Interface.Selections.TextBoxSelection
class CopySelectionBehavior is FormBehavior
action Run(BehaviorEvent event)
Page page = GetPage()
TextBox source = page:GetTextBox("Source notes")
TextBox target = page:GetTextBox("Copied notes")
if source = undefined or target = undefined
return now
end
TextBoxSelection selection = source:GetSelection()
if selection:IsEmpty()
output "Select some text in the source notes first."
else
target:AppendToText(selection:GetText())
end
end
end
A person can select text with the mouse, or by holding Shift and pressing the arrow keys. The selection stays when the focus moves to the button.
Line numbers
A gutter is a strip down the left side of a text box. The most common one
shows line numbers, as in a code editor. Quorum has a LineNumberGutter you
can add with the text box's Add action. A gutter is also a kind of control,
so the code uses cast to tell Quorum which Add action you mean:
LineNumberGutter gutter
source:Add(cast(Gutter, gutter))
A gutter can also react when a person clicks it. A gutter listener is
told which line was clicked. This one moves the caret, the blinking mark
where typing goes, to the start of that line. Make GoToLineListener.quorum:
use Libraries.Interface.Events.GutterListener
use Libraries.Interface.Events.GutterEvent
use Libraries.Interface.Controls.ScrollableLineControl
use Libraries.Interface.Controls.TextBox
class GoToLineListener is GutterListener
action GutterClicked(GutterEvent event)
ScrollableLineControl control = event:GetControl()
if control is TextBox
TextBox box = cast(TextBox, control)
box:SetCaretPositionToLine(event:GetLine())
end
end
end
Then add it to the gutter, in Main.quorum:
GoToLineListener lineListener
gutter:AddGutterListener(lineListener)
A gutter only reacts to the mouse. A person using a keyboard can't click
it, so every job a gutter does needs a keyboard way too. Here, a text
field and a button go to a line from the keyboard. Make GoToLineBehavior.quorum:
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Forms.Page
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.TextBox
use Libraries.Interface.Controls.TextField
class GoToLineBehavior is FormBehavior
action Run(BehaviorEvent event)
Page page = GetPage()
TextBox source = page:GetTextBox("Source notes")
TextField lineField = page:GetTextField("Line number")
if source = undefined
return now
end
if lineField = undefined
return now
end
text typed = lineField:GetText()
integer line = typed:ParseInteger() - 1
if line >= 0 and line < source:GetLineCount()
source:SetCaretPositionToLine(line)
end
end
end
And add the field and button to Main.quorum, after the source notes:
page:AddLabel("Line number:")
TextField lineField = page:AddTextField("Line number")
lineField:SetDescription("Type a line number, then press Go to line.")
Button goToLine = page:AddButton("Go to line")
GoToLineBehavior goBehavior
goToLine:SetBehavior(goBehavior)
Now there are two ways to do the same thing:
- With the mouse: click a line number in the gutter.
- With the keyboard: press Tab to reach the Line number field, type a
number such as
2, press Tab to reach Go to line, and press Space. The caret moves to the start of line 2. Press Shift+Tab until you are back in the source notes to keep typing there.
People count lines from 1, but a text box counts them from 0, so the
behavior subtracts 1. ParseInteger expects a whole number: typing a word
instead stops the program with an error.
Text styles
A text style changes how part of the text looks. You make a TextStyle,
set its colors and an optional highlight such as TextUnderline, tell it
where to start (SetIndex) and how many characters to cover (SetSize), then
add it to the text box with AddTextStyle. Each style needs a name. This
behavior colors and underlines the selected text. Make StyleBehavior.quorum:
use Libraries.Interface.Forms.FormBehavior
use Libraries.Interface.Forms.Page
use Libraries.Interface.Events.BehaviorEvent
use Libraries.Interface.Controls.TextBox
use Libraries.Interface.Selections.TextBoxSelection
use Libraries.Interface.Controls.TextStyles.TextStyle
use Libraries.Interface.Controls.TextStyles.TextUnderline
use Libraries.Game.Graphics.Color
class StyleBehavior is FormBehavior
integer count = 0
action Run(BehaviorEvent event)
Page page = GetPage()
TextBox source = page:GetTextBox("Source notes")
if source = undefined
return now
end
TextBoxSelection selection = source:GetSelection()
if selection:IsEmpty()
output "Select some text to mark first."
return now
end
Color color
TextUnderline underline
TextStyle style
style:SetColor(color:Red())
style:SetSelectionColor(color:Red())
style:SetHighlight(underline)
style:SetIndex(selection:GetStartIndex())
style:SetSize(selection:GetEndIndex() - selection:GetStartIndex())
count = count + 1
source:AddTextStyle("mark " + count, style)
end
end
The count gives each style its own name. If you type inside styled text,
the new letters take the same style.
A screen reader reads the words, not their color or underline. If a style means something, like "this part is important," also say it in words.
The finished program
Here is the whole program in Main.quorum, with the buttons and the gutter. The
buttons go in a grouping with no title, which puts them side by side in
one row, as in the Groupings tutorial.
use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Forms.Grouping
use Libraries.Interface.Controls.TextBox
use Libraries.Interface.Controls.TextField
use Libraries.Interface.Controls.Button
use Libraries.Interface.Controls.Gutter
use Libraries.Interface.Controls.LineNumberGutter
Form form
Page page = form:GetMainPage()
page:SetTitle("Note Copier")
page:AddLabel("Source notes:")
TextBox source = page:AddTextBox("Source notes")
source:SetDescription("Type or paste text here, then select part of it to copy.")
source:SetText("Select some of this text, then press Copy selection.")
source:SetLayoutRows(6)
LineNumberGutter gutter
source:Add(cast(Gutter, gutter))
GoToLineListener lineListener
gutter:AddGutterListener(lineListener)
page:AddLabel("Line number:")
TextField lineField = page:AddTextField("Line number")
lineField:SetDescription("Type a line number, then press Go to line.")
Button goToLine = page:AddButton("Go to line")
GoToLineBehavior goBehavior
goToLine:SetBehavior(goBehavior)
page:AddLabel("Copied notes:")
TextBox target = page:AddTextBox("Copied notes")
target:SetDescription("Text you copy from the source notes appears here.")
target:SetLayoutRows(6)
Grouping buttons = page:AddGrouping("Note buttons")
Button copy = buttons:AddButton("Copy selection")
copy:SetDescription("Adds the selected source text to the copied notes.")
CopySelectionBehavior copyBehavior
copy:SetBehavior(copyBehavior)
Button mark = buttons:AddButton("Mark selection")
mark:SetDescription("Colors and underlines the selected source text.")
StyleBehavior styleBehavior
mark:SetBehavior(styleBehavior)
Button clear = buttons:AddButton("Clear")
clear:SetDescription("Empties the copied notes.")
ClearBehavior clearBehavior
clear:SetBehavior(clearBehavior)
Button show = buttons:AddButton("Show text")
show:SetDescription("Outputs the copied notes and counts their lines.")
ShowBehavior showBehavior
show:SetBehavior(showBehavior)
form:Display()
Press Tab from the top and notice where the focus goes. It moves through the title, each label and its control, the Go to line button, and then the four buttons in the row, in the order they are on the page. You didn't write any focus code.
When a text box guesses: autocorrect
The text boxes in this tutorial show exactly what a person types. Many text boxes in phones and word processors do more: they run autocorrect, an algorithm that compares each word with a dictionary and changes or marks words it doesn't find. That helps most people fix typing mistakes quickly. But a dictionary that leaves out some names treats those names as mistakes. In 2024, a campaign called I Am Not A Typo checked the names of babies born in Northern Ireland in 2022 against Microsoft's English (UK) dictionary. It found that 42% of the names, such as Fiadh, Meabh, Oisin and Daithi, were marked as wrong. Names of African and Asian origin were also marked more often than others (The Irish Times).
Who benefits from autocorrect, and who is harmed? Whose names were most likely left out of the dictionary, and why might that have happened?
Try it yourself. In a word processor or on a phone, type five names: your own, and four from your school, your family or the news that come from different languages. Write down which ones autocorrect changes or marks as wrong, and one thing you would change about it.
Automation and jobs: self-driving cars
User interfaces, including many of the components in these tutorials, provide a powerful way for humans to ask a machine to do something easily. A textbox can correct text or a button can be told to tell a car to "move." There is nothing good or bad about user interfaces. However, Automation can also do a whole job. Self-driving cars are a current example. Waymo, a US company, runs taxis with no human driver. In a February 2026 post on its own website, Waymo said it was giving more than 400,000 rides every week across six US metropolitan areas, gave 15 million rides in 2025, and was preparing to start in more than 20 more cities in 2026, including Tokyo and London (Waymo). These are the company's own numbers; this tutorial did not find an independent count of them. A regular taxi ride needs a paid driver; a Waymo ride does not.
Driving is a large source of work in the United States. The US Bureau of Labor Statistics (BLS), a government agency that counts jobs, reports for 2025:
- Taxi drivers, shuttle drivers and chauffeurs: 455,700 jobs, with a median pay of $37,960 a year. No formal education credential is needed to start. BLS projects 9% more of these jobs by 2035 (BLS).
- Heavy and tractor-trailer truck drivers: 2,221,200 jobs, with a median pay of $58,640 a year. Most drivers start with truck driving school. BLS projects 4% more of these jobs by 2035 (BLS).
Together, that is more than 2.6 million people whose work is driving. Waymo's taxis do the work of the first group. The technology required to do the latter, however, is similar.
What about jobs created? Here the evidence is much weaker. Waymo says its vehicle factory in Mesa, Arizona, "has created hundreds of jobs" (Waymo). That is a claim from the company. It gives no exact number, doesn't say how the jobs were counted, and this tutorial found no independent source that checks it. Even if it is accurate, "hundreds" means fewer than 1,000. Next to the 455,700 taxi and chauffeur jobs that driverless taxis are built to do, 999 jobs would be less than one quarter of one percent. This tutorial also found no reliable count of how many driving jobs self-driving cars have replaced so far, or of how many new jobs they have created overall.
Engage
In this activity, you discuss how self-driving vehicles could create and replace jobs, in a small group or as a class. There is no programming for this one, although if you want to add such a component, students can create an app with a textbox in it and type their arguments in there. Use the facts in "Automation and jobs: self-driving cars" as your evidence, and say which fact you are using when you make a point. Consider the following in the discussion.
- Are the facts actually facts? Consider the sources of each of the alleged numbers and look at BLS directly. Consider if there are any flaws in the claims.
- What are the sources missing? Think like a scientist or a reporter and imagine the incentives of all of the people making and using the technology
- What do you think the impact will be on society? Overall, what effect do you think the technology will have and what rules or laws might help shape that impact to be positive overall?
To finish, write a paragraph or two with your position. Show it to a partner and consider the points and counterpoints. Then, see if you can find a middle ground between any positions you had, if they were different.
Wrap up
A text box holds many lines of text. You can read and change the text, work with what a person selected, and add extras like line numbers and styles. Every feature you add should work with the keyboard as well as the mouse, as the line number gutter's "Go to line" does. Think about software you use: what work does it do that a person used to do, and who did that work?