Java Utililty Methods JCheckBox

List of utility methods to do JCheckBox

Description

The list of methods to do JCheckBox are organized into topic(s).

Method

voidlink(final JCheckBox box, final JComponent... comps)
link
update(box, comps);
box.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        update(box, comps);
});
JCheckBoxnewJCheckBox()
new JCheckBox
final JCheckBox[] jCheckBox = new JCheckBox[1];
try {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            jCheckBox[0] = new JCheckBox();
            jCheckBox[0].setBorderPainted(true);
    });
} catch (InterruptedException | InvocationTargetException e) {
return jCheckBox[0];
JCheckBoxnewJCheckBox(String n, char m)
new J Check Box
return newJCheckBox(n, m, false);
voidonCheckBoxChange(JCheckBox field, final Runnable task)
on Check Box Change
field.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        task.run();
});
voidsetDependency(final JCheckBox master, final JCheckBox slave)
Adds dependancy between two check boxes, so that the slave is enabled only when master is checked.
if (master == null || slave == null)
    return;
slave.setEnabled(master.isSelected());
master.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        slave.setEnabled(master.isSelected());
});
...
voidsetSelectedWithClick(JCheckBox checkBox, boolean selected)
Calls #doClick so that events are fired.
checkBox.setSelected(!selected);
checkBox.doClick();
voidupdate(JCheckBox box, JComponent... comps)
update
for (JComponent comp : comps) {
    comp.setEnabled(box.isSelected());
voidupdateCheckBoxState(final JCheckBox aCheckBox, final boolean aEnabled)
Updates the enabled state of the given checkbox.
if (!aEnabled) {
    aCheckBox.setSelected(false);
aCheckBox.setEnabled(aEnabled);