Java JCheckbox Class Example

JCHECKBOX

Java Swing Tutorial Explaining the JCheckBox Component. JCheckBox is not a member of a checkbox group. A checkbox can be selected and deselected, and it also displays its current state.

JCheckBox Source CodeNote: Help for getting the below source code is taken from Java Sun Website

import java.awt.*;import java.awt.event.*;import javax.swing.*;publicclassJCheckBoxDemoextendsJPanel{//Four accessory choices provide for 16 different combinationsJCheckBox jcbChin;JCheckBox jcbGlasses;JCheckBox jcbHair;JCheckBox jcbTeeth;/* The image for each combination is contained in a
separate image file whose name indicates the accessories.
The filenames are "geek-XXXX.gif" where XXXX can be one
* of the following 16 choices.
*/StringBuffer choices;JLabel jlbPicture;CheckBoxListener myListener =null;publicJCheckBoxDemo(){// Add an item listener for each of the check boxes.// This is the listener class which contains business logic
myListener =newCheckBoxListener();// Create check boxes with default selection true
jcbChin =newJCheckBox("Chin");
jcbChin.setMnemonic(KeyEvent.VK_C);</span>