Java JCheckBox createCheckBox(final String title, final Preferences node, final String pref_name, final boolean default_val)

Here you can find the source of createCheckBox(final String title, final Preferences node, final String pref_name, final boolean default_val)

Description

create Check Box

License

Open Source License

Declaration

public static JCheckBox createCheckBox(final String title, final Preferences node, final String pref_name,
            final boolean default_val) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;

import java.util.prefs.Preferences;

public class Main {
    public static JCheckBox createCheckBox(final String title, final Preferences node, final String pref_name,
            final boolean default_val) {
        final JCheckBox check_box = new JCheckBox(title);
        check_box.addActionListener(new ActionListener() {
            @Override//ww  w  .  ja  va  2s  .  c o m
            public void actionPerformed(final ActionEvent ae) {
                node.putBoolean(pref_name, check_box.isSelected());
            }
        });
        check_box.setSelected(node.getBoolean(pref_name, default_val));
        node.addPreferenceChangeListener(new PreferenceChangeListener() {
            @Override
            public void preferenceChange(final PreferenceChangeEvent evt) {
                if (evt.getNode().equals(node) && evt.getKey().equals(pref_name)) {
                    check_box.setSelected(Boolean.valueOf(evt.getNewValue()));
                }
            }
        });
        return check_box;
    }
}

Related

  1. addCheckBox(Container container, String label, String placement, boolean debug)
  2. convertToYesNo(JCheckBox checkBox)
  3. createCheckBox(String name, String command, boolean selected)
  4. createCheckBox(String s, boolean b)
  5. createJCheckBox(Rectangle bounds)
  6. exclusive(final JCheckBox first, final boolean firstState, final JCheckBox second, final boolean secondState)