javax.swing JCheckBox is a graphical user interface component that represents a check box, which can be checked or unchecked by the user. It is a part of the javax.swing package library.
Examples:
1. Creating a JCheckBox:
JCheckBox checkBox = new JCheckBox("This is a check box");
This will create a check box with the text "This is a check box".
2. Setting the state of a JCheckBox:
checkBox.setSelected(true);
This will set the state of the check box to be checked.
3. Adding a listener to a JCheckBox:
checkBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if (checkBox.isSelected()) System.out.println("Check box is selected"); else System.out.println("Check box is not selected"); } });
This will add an action listener to the check box, which will print a message to the console when the state of the check box changes.
Overall, JCheckBox is a useful component for creating graphical user interfaces in Java applications.
Java JCheckBox - 30 examples found. These are the top rated real world Java examples of javax.swing.JCheckBox extracted from open source projects. You can rate examples to help us improve the quality of examples.