Java JCheckBox

Java JCheckBox

Java JCheckBox
JCheckBox class inherits from JToggleButton.It's used to turn a particular option either true or false.


How to Declare JCheckBox  class

[public class JCheckBox extends JToggleButton implements Accessible]

JCheckBox commonly used constructors

Below are commonly used JCheckBox constructor.
  • JCheckBox()-creates check box button with no text or icon.
  • JCheckBox(String s)-creates check box button with a particular text.
  • JCheckBox(String s, boolean selected)-creates checkbox with a string that is selected.
  • JCheckBox(Action a)-creates check box where properties are taken from the Action supplied.

JCheckBox methods

  • [AccessibleContext getAccessibleContext()]-gets accessible context that is related with check box.
  • [protected String paramString()]-returns string representation of check box.

See also:Java JPasswordField

Java JCheckBox Example

[
import javax.swing.JFrame;
import javax.swing.JCheckBox;
public class JCheckBoxExample extends JFrame{

    JCheckBoxExample()
    {
        super("JCheckBox Example");
        JCheckBox box1 = new JCheckBox("Eclipse IDE");
        box1.setBounds(100,100, 100,50);
        JCheckBox box2 = new JCheckBox("NetBeans", true);
        box2.setBounds(100,150, 100,50);
        add(box1);
        add(box2);
        setLocationRelativeTo(null);
        setSize(400,400);
        setLayout(null);
        setVisible(true);

    }
    public static void main(String args[])
    {
        new JCheckBoxExample();
    }
}
]


Output


See also: Java JTextArea

Java JCheckBox Example with ItemListener

[
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class JCheckBoxExample extends JFrame{

    JCheckBoxExample()
    {
        super("JCheckBox Example");
        JLabel l = new JLabel("");
        l.setHorizontalAlignment(JLabel.CENTER);
        l.setSize(400,100);
        add(l);
        JCheckBox box1 = new JCheckBox("Eclipse IDE");
        box1.setBounds(100,100, 100,50);

        box1.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                l.setText("Eclipse IDE: "                      
  + (e.getStateChange()==1?"checked":"unchecked"));
            }
        });

        JCheckBox box2 = new JCheckBox("NetBeans", true);
        box2.setBounds(100,150, 100,50);
        box2.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                l.setText("NetBeans: "                    
    + (e.getStateChange()==1?"checked":"unchecked"));
            }
        });
        add(box1);
        add(box2);
        setLocationRelativeTo(null);
        setSize(400,400);
        setLayout(null);
        setVisible(true);

    }
    public static void main(String args[])
    {
        new JCheckBoxExample();
    }
}
]


Output

Java JCheckBox Example with ItemListener

See also: Java JButton

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Java JCheckBox
Java JCheckBox
Java JCheckBox
https://4.bp.blogspot.com/-lcgyv3VfvYo/WL5Z5GkuCdI/AAAAAAAAHEU/Ef2mIWI23IwbW3XmHaL3brqVe6hs63lNwCLcB/s200/Java-JCheckBox-min.PNG
https://4.bp.blogspot.com/-lcgyv3VfvYo/WL5Z5GkuCdI/AAAAAAAAHEU/Ef2mIWI23IwbW3XmHaL3brqVe6hs63lNwCLcB/s72-c/Java-JCheckBox-min.PNG
Java Codes
http://www.download-all.net/2017/03/java-jcheckbox.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/03/java-jcheckbox.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy