CJCoding With Joseph
15free / daySign inCreate account

Thompson Rivers University

Adding a Warning Label

Assignment 5 User Interfaces FX - SM 2025

Before we add the sound behavior, let’s add the final visible component: the warning label at the bottom of the window.

This label will always be visible and should clearly tell the user not to click anywhere else in the window. It will be written in red text, centered, and shown at the bottom of the app. Here’s the message we’ll display:

Select the radio buttons or the slider only.
You'll hear a warning sound if the mouse is clicked elsewhere!


Create the Warning Label

We’ll create a new Label and give it two lines of text using \n. We’ll also:

  • Set the text color to red using setTextFill(...)

  • Make it bold and readable with a smaller font size than the main instruction label

  • Center the lines within the label using setTextAlignment(...)

Label warningLabel = new Label(
    "Select the radio buttons or the slider only.\n" +
    "You'll hear a warning sound if the mouse is clicked elsewhere!"
);
warningLabel.setTextFill(Color.RED);
warningLabel.setFont(Font.font("System", FontWeight.BOLD, 14));
warningLabel.setTextAlignment(TextAlignment.CENTER);
Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 54 more lessons in Thompson Rivers University.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.