Here you can find the source of createCheckBox(final String title, final Preferences node, final String pref_name, final boolean default_val)
public static JCheckBox createCheckBox(final String title, final Preferences node, final String pref_name, final boolean default_val)
//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; } }