CheckBoxes | How to use CheckBox in Java | Checkbox | Java Checkbox in netbeans | JCheckBox
Programming Guru
How to use checkbox in java. In this tutorial we are going to learn about Checkbox in java netbeans. A checkbox is very important UI component in Java swing. jCheckbox in java is used to select multiple option in a multiple choice question. for example we have multiple checkboxes in Java that represent skill of multiple types. checkbox one is a Java checkbox. jcheckbox two is C# checkbox. jcheckbox three is javascript checkbox. jcheckbox four is Php checkbox and so on. so in this example we can select between multiple checkboxes.
Java JCheckBox The JCheckBox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a CheckBox in java changes its state from "on" to "off" or from "off" to "on ".It inherits JToggleButton class. Java CheckBox class declaration Let's see the declaration for javax.swing.JCheckBox class. Java Swing | JCheckBox with examples JCheckBox is a part of Java Swing package . JCheckBox can be selected or deselected . It displays it state to the user . JCheckBox is an implementation to checkbox . JCheckBox inherits JToggleButton class. JCheckBox() : creates a new checkbox with no text or icon JCheckBox(Icon i) : creates a new checkbox with the icon specified JCheckBox(Icon icon, boolean s) : creates a new checkbox with the icon specified and the boolean value specifies whether it is selected or not. JCheckBox(String t) :creates a new checkbox with the string specified JCheckBox(String text, boolean selected) :creates a new checkbox with the string specified and the boolean value specifies whether it is selected or not. JCheckBox(String text, Icon icon) :creates a new checkbox with the string and the icon specified. JCheckBox(String text, Icon icon, boolean selected): creates a new checkbox with the string and the icon specified and the boolean value specifies whether it is selected or not.
Methods to add Item Listener to checkbox.
addActionListener(ItemListener l): adds item listener to the component
itemStateChanged(ItemEvent e) : abstract function invoked when the state of the item to which listener is applied changes
getItem() : Returns the component-specific object associated with the item whose state changed
getStateChange() : Returns the new state of the item. The ItemEvent class defines two states: SELECTED and DESELECTED.
getSource() : Returns the component that fired the item event.
Commonly used methods:
setIcon(Icon i) : sets the icon of the checkbox to the given icon
setText(String s) :sets the text of the checkbox to the given text
setSelected(boolean b) : sets the checkbox to selected if boolean value passed is true or vice versa
getIcon() : returns the image of the checkbox
getText() : returns the text of the checkbox
updateUI() : resets the UI property with a value from the current look and feel.
getUI() : returns the look and feel object that renders this component.
paramString() : returns a string representation of this JCheckBox.
getUIClassID() : returns the name of the Look and feel class that renders this component.
getAccessibleContext() : gets the AccessibleContext associated with this JCheckBox.
isBorderPaintedFlat() : gets the value of the borderPaintedFlat property.
setBorderPaintedFlat(boolean b) : sets the borderPaintedFlat.
Checkbox in Java Example The java checkbox, as it is also known java swing Checkbox component is a component used to plot an option which can be connected (on = true) or off (off = false). It is usually used to display a set of options which can be selected independently by the user, or allow multiple selections.
Follow my Facebook Page : https://www.facebook.com/105940115222549 Follow me on Instagram : https://www.instagram.com/p/CViUlw2sOMi Follow me on tumblr : http://programming-guru.tumblr.com Follow me on reddit : https://www.reddit.com/u/Programming_guru1?utm_medium=android_app&utm_source=share ... https://www.youtube.com/watch?v=-TdJM4-rh4k
49074422 Bytes