Here you can find the source of createComboBox(final Preferences node, final String pref_name, final String[] options, final String default_value)
public static JComboBox createComboBox(final Preferences node, final String pref_name, final String[] options, final String default_value)
//package com.java2s; //License from project: Open Source License import javax.swing.JComboBox; import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.prefs.Preferences; public class Main { public static JComboBox createComboBox(final Preferences node, final String pref_name, final String[] options, final String default_value) { final String[] interned_options = new String[options.length]; for (int i = 0; i < options.length; ++i) { interned_options[i] = options[i].intern(); }/*from ww w. j a va 2s. c o m*/ default_value.intern(); final JComboBox combo_box = new JComboBox(interned_options); final String current_stored_value = node.get(pref_name, default_value).intern(); combo_box.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { final String selection = (String) combo_box.getSelectedItem(); if (selection != null) { node.put(pref_name, selection); } } }); combo_box.setSelectedItem(current_stored_value); node.addPreferenceChangeListener(new PreferenceChangeListener() { @Override public void preferenceChange(final PreferenceChangeEvent evt) { if (evt.getNode().equals(node) && evt.getKey().equals(pref_name) && !combo_box.getSelectedItem().equals(evt.getNewValue()) && evt.getNewValue() != null) { combo_box.setSelectedItem(evt.getNewValue().intern()); } } }); return combo_box; } }