Java Swing Interface Programming (28) --- check box: JCheckBox

Source: Internet
Author: User

The program can use JRadioButton to implement the single-choice button function. To implement the check box function, JCheckBox must be used.

Package com. beyole. util; import java. awt. container; import java. awt. gridLayout; import java. awt. event. windowAdapter; import java. awt. event. using wevent; import javax. swing. borderFactory; import javax. swing. JCheckBox; import javax. swing. JFrame; import javax. swing. JPanel; class MyCheckBox {private JFrame frame = new JFrame ("Beyole"); // defines the form private Container container = frame. getContentPane (); // get the form container private JCheckBox jcb1 = new JCheckBox (""); // define a check box private JCheckBox jcb2 = new JCheckBox (" "); // define a check box private JCheckBox jcb3 = new JCheckBox ("blog"); // define a check box private JPanel = new JPanel (); // define a panel public MyCheckBox () {panel. setBorder (BorderFactory. createTitledBorder ("select your favorite website"); // defines a panel's border display panel. setLayout (new GridLayout (1, 3); // defines the layout, with one row and three columns of panel. add (this. jcb1); // Add the component panel. add (this. jcb2); // Add the component panel. add (this. jcb3); // Add the component container. add (panel); // add the panel this. frame. setSize (330, 80); // defines the size of the form. this. frame. setVisible (true); // display the form this. frame. addWindowListener (new WindowAdapter () {public void windowClosing (invalid wevent arg0) // Method for closing the rewrite window {System. exit (1); // exit});} public class JCheckBoxDemo01 {public static void main (String [] args) {new MyCheckBox ();}}

It can be found that, unlike the single-choice button, the selected area is changed to a box.

Program:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.