CJCoding With Joseph
15free / daySign inCreate account

Thompson Rivers University

Adding the Radio Buttons and Color Options

Assignment 5 User Interfaces FX - SM 2025

Now let’s add the three color options using radio buttons. These will let the user pick the color of the square. We want them to behave so that only one can be selected at a time.

To do that, we need to create three radio buttons and place them in something called a ToggleGroup.


Create the Radio Buttons

Each button is created using the RadioButton class. You just pass in the label text you want to appear next to the button.

RadioButton redRB = new RadioButton("Red");
RadioButton greenRB = new RadioButton("Green");
RadioButton orangeRB = new RadioButton("Orange");

This gives us three buttons for "Red", "Green", and "Orange".


Group Them with a ToggleGroup

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.