JRadioButton & ItemListener

Our example shows three radio buttons in a form. A user can select any one of these radio buttons and only one radio button will be in the selected state. Above, the radio button three is in the selected state. When a radio button is in checked (selected) state, our example will flash a message box stating which radio button is in the selected state. Here in this example, we will create all these radio buttons using JRadioButton component of the Java Swing.

JToggleButton as Two-State Button

The example contains three components. One is a JLabel which tells in what mode the example is in. The button labelled OFF is the JToggleButton and it will switch the state between Selected & Unselected. The text box tells what kind of the state change is made by the user while he/she clicked the Two-State button last time.

AWT CheckboxMenuItem Example

In this example, we will learn how to use AWT CheckboxMenuItem and Menu Separator. Here, we use our previous example on AWT Menu and change it to create CheckboxMenuItem. We create three checkbox menu items for Circle, Pentagon and Rectangle. In the above picture, we can also see a sunken line running between normal menu items and checked menu items. This line is called a Menu Separator. We create that here as well in this example.