Application Techniques



Using the JRadioButton Control

How to use the Swing radio button control on a form.

About this technique

Details

Category

Java Client Techniques> Version 3 Swing-based controls

Description

You'll learn about:

You can run this technique code from:

NOTE   First make sure that database is running on your localhost SilverStream Server

Related reading

See the chapter on the Form Designer in the Tools Guide

Getting the control state   Top of page

The following code uses the getState() method to determine if a radio button (rbStandardHealth) is currently selected. It then uses setText() to place a corresponding value in a text label lblRBValue.

This code is for the actionPerformed event of rbStandardHealth.

  // If the Standard Health radio button is now selected,  
  // change the label to display the value 'Standard' 
    if (rbStandardHealth.getState()) 
        lblRBValue.setText("Value = Standard"); 

This code sets the button's value programmatically.

  rbStandardHealth.setState(true); 

NOTE   When the user clicks a radio button, a valueChanged event occurs for all the radio buttons in the group. An actionPerformed event occurs for the clicked button. If a radio button's value changes programmatically, a valueChanged event occurs for all the buttons, even if the value does not actually change (for example, the state of more than one button may remain false).






Copyright © 2000, SilverStream Software, Inc. All rights reserved.