Java JComboBox prepareComboBox(JComboBox comboBox, Dimension size, int min, int max, int[] list)

Here you can find the source of prepareComboBox(JComboBox comboBox, Dimension size, int min, int max, int[] list)

Description

prepares comboBox control

License

Open Source License

Parameter

Parameter Description
comboBox reference to the control
size size of the control
min minimum value of the comboBox item
max maximum value of the comboBox item
list list of comboBox items

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void prepareComboBox(JComboBox comboBox, Dimension size,
        int min, int max, int[] list) 

Method Source Code

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

import java.awt.Dimension;
import java.awt.Font;

import java.util.List;

import javax.swing.JComboBox;

public class Main {
    private static final Font fontComboBox = new Font("arial", Font.BOLD,
            12);//from  ww  w.  j a v  a 2 s.  c  om

    /**
     * prepares comboBox control
     * @param comboBox reference to the control
     * @param size size of the control
     * @param min minimum value of the comboBox item 
     * @param max maximum value of the comboBox item
     * @param list list of comboBox items
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void prepareComboBox(JComboBox comboBox, Dimension size,
            int min, int max, int[] list) {

        comboBox.setLayout(null);
        comboBox.setSize(size);
        comboBox.setFont(fontComboBox);
        comboBox.removeAllItems();
        for (; min <= max; min++) {
            comboBox.addItem(min);
        }

        if (list != null) {
            for (int i = 0; i < list.length; i++) {
                comboBox.addItem(list[i]);
            }
        }
    }

    /**
     * prepares comboBox control
     * @param comboBox reference to the control
     * @param size size of the control
     * @param list list of comboBox items
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static void prepareComboBox(JComboBox comboBox, Dimension size,
            List<String> list) {

        comboBox.setLayout(null);
        comboBox.setSize(size);
        comboBox.setFont(fontComboBox);
        comboBox.removeAllItems();

        if (list != null) {
            for (String item : list) {
                comboBox.addItem(item);
            }
        }
    }
}

Related

  1. loadEnum(JComboBox combo, Class c, boolean removeAll)
  2. loadPrefs(Preferences prefs, String prefKey, JComboBox combo)
  3. makeJComboBox(ResourceBundle resource, String panelName, String keyword)
  4. makeSquare(JComboBox... comboBoxes)
  5. newCombo(int chars)
  6. registerBrowseButtonListener(final JComboBox comboBox, final JButton button, final boolean chooseFile, final boolean isOpen, final FileFilter fileFilter, final File initialDirectory)
  7. removeAllListeners(JComboBox box)
  8. resetComboBoxInfo(JComboBox jComboBoxField, ArrayList comboBoxArray, String expression)
  9. resetPhaseBox(JComboBox phaseBox)