Java Utililty Methods JComboBox

List of utility methods to do JComboBox

Description

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

Method

booleanisEmptyStr(javax.swing.JComboBox input)
Check if the JComboBox selection is empty
String str = (String) input.getSelectedItem();
return str == null || "".equals(str.trim());
booleanisJComboBoxNotEmpty(javax.swing.JComboBox combo)
is J Combo Box Not Empty
return !((String) combo.getSelectedItem()).trim().isEmpty();
booleanlargeThan(javax.swing.JComboBox input, double x)
Check if the JComboBox input is larger than x
double d = new Double((String) (input.getSelectedItem())).doubleValue();
if (d > x)
    return true;
return false;
voidloadComboBox(JComboBox combo, List list)
load Combo Box
loadComboBox(combo, list, true);
voidloadEnum(JComboBox combo, Class c, boolean removeAll)
load Enum
if (removeAll) {
    combo.removeAllItems();
for (E e : c.getEnumConstants()) {
    combo.addItem(e);
voidloadPrefs(Preferences prefs, String prefKey, JComboBox combo)
load Prefs
DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
String recents = prefs.get(prefKey, null);
if (recents != null) {
    StringTokenizer st = new StringTokenizer(recents, DELIMITER);
    while (st.hasMoreTokens()) {
        comboModel.addElement(st.nextToken());
combo.setModel(comboModel);
JComboBoxmakeJComboBox(ResourceBundle resource, String panelName, String keyword)
make J Combo Box
String value = null;
try {
    value = resource.getString(panelName + "_COMBOBOX_" + keyword + "_DEFAULT");
} catch (MissingResourceException e) {
JComboBox<String> jcb = new JComboBox<>();
String val = null;
int ii = 0;
...
voidmakeSquare(JComboBox... comboBoxes)
Sets the given combo boxes to appear in the square style.
for (JComboBox<?> comboBox : comboBoxes) {
    comboBox.putClientProperty("JComboBox.isSquare", true);
JComboBoxnewCombo(int chars)
new Combo
StringBuilder sb = new StringBuilder(chars);
while (chars-- > 0)
    sb.append("X");
JComboBox<String> combo = new JComboBox<String>();
combo.setPrototypeDisplayValue(sb.toString());
return combo;
voidprepareComboBox(JComboBox comboBox, Dimension size, int min, int max, int[] list)
prepares comboBox control
comboBox.setLayout(null);
comboBox.setSize(size);
comboBox.setFont(fontComboBox);
comboBox.removeAllItems();
for (; min <= max; min++) {
    comboBox.addItem(min);
if (list != null) {
...