{"id":31031,"date":"2016-01-06T11:00:07","date_gmt":"2016-01-06T09:00:07","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=31031"},"modified":"2016-01-05T12:55:48","modified_gmt":"2016-01-05T10:55:48","slug":"java-swing-checkbox-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/","title":{"rendered":"Java Swing Checkbox Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In this article, Java swing checkbox will be discussed. <code>checkbox<\/code> is to present whether an item has been selected or unselected. In Java swing, <code>JCheckBox<\/code> is the component to fulfill this function. Different actions could be performed, and different states could also be displayed to the users, if we add action listener or action handler to the <code>checkbox<\/code>.<\/p>\n<p>In Java swing, <code>JCheckBox<\/code> is inherited from <code>AbstractButton<\/code> and <code>JToggleButton<\/code>. It inherits all the methods from its parent classes. It could be constructed through following constructors:<\/p>\n<ul>\n<li>JCheckBox(): creates an checkbox without text nor icon<\/li>\n<li>JCheckBox(Action e): creates an checkbox where properties are taken from the provided action<\/li>\n<li>JCheckBox(Icon icon): creates an checkbox with an icon<\/li>\n<li>JCheckBox(Icon icon, boolean selected): creates an checkbox with an icon and specifies whether this icon has been selected or not<\/li>\n<li>JCheckBox(String text): creates an checkbox with text<\/li>\n<li>JCheckBox(String text, boolean selected):\u00a0creates an checkbox with text\u00a0and specifies whether this text has been selected or not<\/li>\n<li>JCheckBox(String text, Icon icon):\u00a0creates an checkbox with an icon and text<\/li>\n<li>JCheckBox(String text,\u00a0Icon icon, boolean selected):\u00a0\u00a0creates an checkbox with text and icon, and specifies whether these two have been selected or not<\/li>\n<\/ul>\n<p>Further detailed information about the <code>JCheckBox<\/code> could be referred to the <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JCheckBox.html\" target=\"_blank\">official Oracle documents<\/a>.<\/p>\n<h2>2. Examples on java swing checkbox<\/h2>\n<p>For the following example parts on <code>JCheckBox<\/code>, Java 8 and Eclipse IDE (version Mars 4.5.0) are used.<\/p>\n<h3>2.1 Simple example of java swing checkbox<\/h3>\n<p>In this example, five <code>JCheckBox<\/code> are created, added to the panel and frame, with the title to be set to &#8220;Fruits&#8221;. Five different fruits are named by &#8220;Apple&#8221;, &#8220;Banana&#8221;, &#8220;Grape&#8221;, &#8220;Orange&#8221; and &#8220;Pear&#8221;. Then these can be selected by the <code>checkbox<\/code>.<\/p>\n<p>Below is the Java code for this example:<\/p>\n<p><span style=\"text-decoration: underline\"><em>simpleCheckbox.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package javaCodeGeeks;\r\n\r\n\/*\r\n * A simple swing checkbox example with different constructors\r\n *\/\r\n\r\nimport javax.swing.JFrame;\r\nimport javax.swing.JPanel;\r\nimport javax.swing.BorderFactory;\r\nimport javax.swing.JCheckBox;\r\n\r\npublic class simpleCheckbox {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t\/\/ Create and set up a frame window\r\n\t\tJFrame.setDefaultLookAndFeelDecorated(true);\r\n\t\tJFrame frame = new JFrame(\"Simple checkbox demo\");\r\n\t\tframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r\n\t\t\r\n\t\t\/\/ Define the panel to hold the checkbox\t\r\n\t\tJPanel panel = new JPanel();\r\n\t\t\r\n\t\t\/\/ Create checkbox with different constructors\r\n\t\tJCheckBox checkbox1 = new JCheckBox(\"Apple\", true);\r\n\t\tJCheckBox checkbox2 = new JCheckBox(\"Banana\");\t\t\r\n\t\tJCheckBox checkbox3 = new JCheckBox(\"Grape\", true);\r\n\t\tJCheckBox checkbox4 = new JCheckBox(\"Orange\");\r\n\t\tJCheckBox checkbox5 = new JCheckBox(\"Pear\", true);\r\n\t\t\r\n\t\t\/\/ Set up the title for the panel\r\n\t\tpanel.setBorder(BorderFactory.createTitledBorder(\"Fruits\"));\r\n\t\t\r\n\t\t\/\/ Add the checkbox into the panels \r\n\t\tpanel.add(checkbox1);\r\n\t\tpanel.add(checkbox2);\r\n\t\tpanel.add(checkbox3);\r\n\t\tpanel.add(checkbox4);\r\n\t\tpanel.add(checkbox5);\r\n\t\t\r\n\t\t\/\/ Add the panel into the frame\r\n\t\tframe.add(panel);\r\n\t\t\r\n\t\t\/\/ Set the window to be visible as the default to be false\r\n\t\tframe.pack();\r\n\t\tframe.setVisible(true);\r\n\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>Run this code, and following result should show up:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><figure id=\"attachment_31044\" aria-describedby=\"caption-attachment-31044\" style=\"width: 770px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/simpleCheckbox.jpg\"><img decoding=\"async\" class=\"wp-image-31044 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/simpleCheckbox.jpg\" alt=\"simpleCheckbox\" width=\"770\" height=\"154\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/simpleCheckbox.jpg 770w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/simpleCheckbox-300x60.jpg 300w\" sizes=\"(max-width: 770px) 100vw, 770px\" \/><\/a><figcaption id=\"caption-attachment-31044\" class=\"wp-caption-text\">simple Checkbox demo<\/figcaption><\/figure><\/p>\n<p>As we can see from the above figure, &#8220;Apple&#8221;, &#8220;Grape&#8221; and &#8220;Pear&#8221; are selected automatically, while &#8220;Banana&#8221; and &#8220;Orange&#8221; not. The reason for this is we have set the three fruits to be selected, while the other two not. The following code could explain the difference.<\/p>\n<pre class=\"brush:java\">\t\tJCheckBox checkbox1 = new JCheckBox(\"Apple\", true);\r\n\t\tJCheckBox checkbox2 = new JCheckBox(\"Banana\");\r\n<\/pre>\n<h3>2.2 Other settings on checkbox<\/h3>\n<p>As we\u2019ve described in introduction part, that <code>JCheckBox<\/code> is inherited from <code>AbstractButton<\/code> and <code>JToggleButton<\/code>, we can have different settings on <code>checkbox<\/code>.<\/p>\n<p>For example, we can set font for different <code>checkbox<\/code> with the code similar to the following:<\/p>\n<pre class=\"brush:java\">checkbox1.setFont(new java.awt.Font(\"Arial\", Font.BOLD, 18));\r\n<\/pre>\n<p>In this example, we&#8217;ve set the font for the <code>checkbox<\/code> &#8220;Apple&#8221; to be &#8220;Arial&#8221; with the font to be 18 and bolded. The effect of this setting can be shown as below:<\/p>\n<p><figure id=\"attachment_31098\" aria-describedby=\"caption-attachment-31098\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/font.jpg\"><img decoding=\"async\" class=\"wp-image-31098 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/font.jpg\" alt=\"font\" width=\"800\" height=\"166\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/font.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/font-300x62.jpg 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-31098\" class=\"wp-caption-text\">Font setting on checkbox<\/figcaption><\/figure><\/p>\n<p>Also, we can set the background and foreground with different colors. For example, we can set the color of <code>checkbox<\/code> &#8220;Banana&#8221; to be &#8220;RED&#8221; with the following code:<\/p>\n<pre class=\"brush:java\">checkbox2.setForeground(Color.RED);\r\n<\/pre>\n<p>The result of this setting is shown below:<\/p>\n<p><figure id=\"attachment_31097\" aria-describedby=\"caption-attachment-31097\" style=\"width: 752px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/color.jpg\"><img decoding=\"async\" class=\"wp-image-31097 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/color.jpg\" alt=\"color\" width=\"752\" height=\"156\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/color.jpg 752w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/color-300x62.jpg 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/a><figcaption id=\"caption-attachment-31097\" class=\"wp-caption-text\">Color setting on checkbox<\/figcaption><\/figure><\/p>\n<p>Lastly, we can set the mnemonic key by specifying the key code defined in <code>java.wt.event.KeyEvent<\/code>. For instance, keyboard &#8216;A&#8217; could be set to mnemonic key by following code:<\/p>\n<pre class=\"brush:java\">\t\tcheckbox1.setMnemonic(KeyEvent.VK_A);\r\n\t\tcheckbox1.setSelected(true);\r\n<\/pre>\n<p>The result for this setting is that you can use the keyboard &#8216;alt&#8217; and &#8216;A&#8217; to select or unselect the specified <code>checkbox<\/code>. Figure below shows this effect:<\/p>\n<p><figure id=\"attachment_31096\" aria-describedby=\"caption-attachment-31096\" style=\"width: 750px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/mnemonic.jpg\"><img decoding=\"async\" class=\"wp-image-31096 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/mnemonic.jpg\" alt=\"mnemonic\" width=\"750\" height=\"146\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/mnemonic.jpg 750w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/mnemonic-300x58.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption id=\"caption-attachment-31096\" class=\"wp-caption-text\">Mnemonic setting on checkbox<\/figcaption><\/figure><\/p>\n<h3>2.3 Checkbox with event listener<\/h3>\n<p>For <code>checkbox<\/code>, the more common usage should be combining it with event listener. With the event listener added, the <code>checkbox<\/code> can act different actions.<\/p>\n<p>In the following example, we have different names (&#8220;Alex&#8221;, &#8220;Jessica&#8221;, &#8220;Lily&#8221;, &#8220;Steven&#8221;) on panel1. When we click any name, the output panel shows that the name is selected. However, when we unselect the name, the output panel shows that the name is unselected.<\/p>\n<p>Below is the Java code for this example:<\/p>\n<p><span style=\"text-decoration: underline\"><em>checkboxWithEvent.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package javaCodeGeeks;\r\n\r\n\/*\r\n * A checkbox example with event listener\r\n *\/\r\n\r\nimport javax.swing.JFrame;\r\nimport javax.swing.JLabel;\r\nimport javax.swing.JPanel;\r\nimport javax.swing.BorderFactory;\r\nimport javax.swing.JCheckBox;\r\n\r\nimport java.awt.GridLayout;\r\nimport java.awt.event.ItemEvent;\r\nimport java.awt.event.ItemListener;\r\n\r\npublic class checkboxWithEvent {\t\r\n\t\/\/ Create different checkbox\r\n\tpublic static JCheckBox checkbox1 = new JCheckBox(\"Alex\");\r\n\tpublic static JCheckBox checkbox2 = new JCheckBox(\"Jessica\");\r\n\tpublic static JCheckBox checkbox3 = new JCheckBox(\"Lily\");\t\t\r\n\tpublic static JCheckBox checkbox4 = new JCheckBox(\"Steven\");\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t\/\/ Create and set up a frame window\r\n\t\tJFrame.setDefaultLookAndFeelDecorated(true);\r\n\t\tJFrame frame = new JFrame(\"Checkbox with event listener\");\r\n\t\tframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r\n\t\t\r\n\t\t\/\/ Define the panel to hold the checkbox\t\r\n\t\tJPanel panel1 = new JPanel();\r\n\t\tJPanel panel2 = new JPanel();\r\n\t\tJLabel msg = new JLabel(\"\", JLabel.CENTER);\r\n\t\t\t\r\n\t\t\/\/ Set up the title for the panel\r\n\t\tpanel1.setBorder(BorderFactory.createTitledBorder(\"Name\"));\t\r\n\t\tpanel2.setBorder(BorderFactory.createTitledBorder(\"Output\"));\t\t\r\n\t\t\r\n\t\t\/\/ Add the checkbox into the panels \t\r\n\t\tpanel1.add(checkbox1);\r\n\t\tpanel1.add(checkbox2);\r\n\t\tpanel1.add(checkbox3);\r\n\t\tpanel1.add(checkbox4);\r\n\t\t\r\n\t\tpanel2.add(msg);\r\n\t\t\r\n\t\t\/\/ Add action listener\r\n\t\tcheckbox1.addItemListener(new ItemListener() {\r\n\t\t\tpublic void itemStateChanged(ItemEvent e) {\r\n\t\t\t\tif (e.getStateChange() == 1) {\r\n\t\t\t\t\tmsg.setText(\"Alex is selected\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tmsg.setText(\"Alex is unselected\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\tcheckbox2.addItemListener(new ItemListener() {\r\n\t\t\tpublic void itemStateChanged(ItemEvent e) {\r\n\t\t\t\tif (e.getStateChange() == 1) {\r\n\t\t\t\t\tmsg.setText(\"Jessica is selected\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tmsg.setText(\"Jessica is unselected\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t\tcheckbox3.addItemListener(new ItemListener() {\r\n\t\t\tpublic void itemStateChanged(ItemEvent e) {\r\n\t\t\t\tif (e.getStateChange() == 1) {\r\n\t\t\t\t\tmsg.setText(\"Lily is selected\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tmsg.setText(\"Lily is unselected\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t\tcheckbox4.addItemListener(new ItemListener() {\r\n\t\t\tpublic void itemStateChanged(ItemEvent e) {\r\n\t\t\t\tif (e.getStateChange() == 1) {\r\n\t\t\t\t\tmsg.setText(\"Steven is selected\");\r\n\t\t\t\t} else {\r\n\t\t\t\t\tmsg.setText(\"Steven is unselected\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t\t\/\/ Add the panel into the frame\r\n\t\tframe.setLayout(new GridLayout(2, 1));\r\n\t\tframe.add(panel1);\r\n\t\tframe.add(panel2);\r\n\t\t\r\n\t\t\/\/ Set the window to be visible as the default to be false\r\n\t\tframe.pack();\r\n\t\tframe.setVisible(true);\r\n\t}\r\n\t\r\n}\r\n<\/pre>\n<p>When we run this code, we can see the result below with nothing in the output panel.<\/p>\n<p><figure id=\"attachment_31103\" aria-describedby=\"caption-attachment-31103\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/output.jpg\"><img decoding=\"async\" class=\"wp-image-31103 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/output.jpg\" alt=\"output\" width=\"594\" height=\"272\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/output.jpg 594w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/output-300x137.jpg 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/a><figcaption id=\"caption-attachment-31103\" class=\"wp-caption-text\">Output with nothing<\/figcaption><\/figure><\/p>\n<p>However, after we select the <code>checkbox<\/code> of Alex, the output shows that Alex is selected as below:<\/p>\n<p><figure id=\"attachment_31102\" aria-describedby=\"caption-attachment-31102\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/selected.jpg\"><img decoding=\"async\" class=\"wp-image-31102 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/selected.jpg\" alt=\"selected\" width=\"594\" height=\"272\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/selected.jpg 594w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/selected-300x137.jpg 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/a><figcaption id=\"caption-attachment-31102\" class=\"wp-caption-text\">Checkbox selected<\/figcaption><\/figure><\/p>\n<p>Then we unselected Alex, the output shows that Alex is unselected:<\/p>\n<p><figure id=\"attachment_31101\" aria-describedby=\"caption-attachment-31101\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/unselected.jpg\"><img decoding=\"async\" class=\"wp-image-31101 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/unselected.jpg\" alt=\"unselected\" width=\"594\" height=\"272\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/unselected.jpg 594w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/unselected-300x137.jpg 300w\" sizes=\"(max-width: 594px) 100vw, 594px\" \/><\/a><figcaption id=\"caption-attachment-31101\" class=\"wp-caption-text\">Checkbox unselected<\/figcaption><\/figure><\/p>\n<p>The final note for the Java swing checkbox is the difference between <code>checkbox<\/code> and <code>radio button<\/code>. For <code>checkbox<\/code>, we can select multiple <code>checkbox<\/code>, while in <code>radio button<\/code>, only one button can be selected at one time.<\/p>\n<h2>3. Download the Source Code<\/h2>\n<p>This was an example of Checkbox in Java Swing.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/12\/checkboxexample.zip\">checkboxexample.zip<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java swing, JCheckBox is the component to fulfill this function. Different actions could be performed, and different states could also be displayed to the users, if we add action listener or &hellip;<\/p>\n","protected":false},"author":73,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[264],"class_list":["post-31031","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swing","tag-checkbox"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Swing Checkbox Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Swing Checkbox Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-06T09:00:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jun Wu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jun Wu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\"},\"author\":{\"name\":\"Jun Wu\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678\"},\"headline\":\"Java Swing Checkbox Example\",\"datePublished\":\"2016-01-06T09:00:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\"},\"wordCount\":747,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"Checkbox\"],\"articleSection\":[\"swing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\",\"name\":\"Java Swing Checkbox Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2016-01-06T09:00:07+00:00\",\"description\":\"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Desktop Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"swing\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Java Swing Checkbox Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678\",\"name\":\"Jun Wu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg\",\"caption\":\"Jun Wu\"},\"description\":\"Jun (Steven) Wu is a current Master student in Computer Science &amp; Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.\",\"sameAs\":[\"https:\/\/wuxiaomin98.wordpress.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jun-wu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java Swing Checkbox Example - Java Code Geeks","description":"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/","og_locale":"en_US","og_type":"article","og_title":"Java Swing Checkbox Example - Java Code Geeks","og_description":"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-01-06T09:00:07+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Jun Wu","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jun Wu","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/"},"author":{"name":"Jun Wu","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678"},"headline":"Java Swing Checkbox Example","datePublished":"2016-01-06T09:00:07+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/"},"wordCount":747,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["Checkbox"],"articleSection":["swing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/","name":"Java Swing Checkbox Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2016-01-06T09:00:07+00:00","description":"1. Introduction In this article, Java swing checkbox will be discussed. checkbox is to present whether an item has been selected or unselected. In Java","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-checkbox-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Desktop Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/"},{"@type":"ListItem","position":4,"name":"swing","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/"},{"@type":"ListItem","position":5,"name":"Java Swing Checkbox Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6593091dba631ca0f41c4ba4e7c97678","name":"Jun Wu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/Jun-Wu-96x96.jpg","caption":"Jun Wu"},"description":"Jun (Steven) Wu is a current Master student in Computer Science &amp; Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.","sameAs":["https:\/\/wuxiaomin98.wordpress.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jun-wu\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/73"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=31031"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/31031\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=31031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=31031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=31031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}