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

JFileChooserregisterBrowseButtonListener(final JComboBox comboBox, final JButton button, final boolean chooseFile, final boolean isOpen, final FileFilter fileFilter, final File initialDirectory)
register Browse Button Listener
if (!comboBox.isEditable()) {
    throw new IllegalArgumentException("The combo box must be editable.");
final JFileChooser fileChooser = new JFileChooser();
ActionListener listener = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        fileChooser.setCurrentDirectory(comboBox.getSelectedItem() == null
                || comboBox.getSelectedItem().toString().trim().length() == 0 ? initialDirectory
...
voidremoveAllListeners(JComboBox box)
remove All Listeners
for (ItemListener al : box.getItemListeners()) {
    box.removeItemListener(al);
voidresetComboBoxInfo(JComboBox jComboBoxField, ArrayList comboBoxArray, String expression)
reset Combo Box Info
if (comboBoxArray.contains(expression)) {
    jComboBoxField.setSelectedItem(expression);
} else {
    jComboBoxField.setSelectedItem(expression.substring(expression.indexOf(".") + 1, expression.length()));
voidresetPhaseBox(JComboBox phaseBox)
refreshing the drop down to include phases of the selected schema by clearing out the previous items and adding new ones
if (!phaseBox.isEnabled())
    phaseBox.setEnabled(true);
while (phaseBox.getItemCount() != 1) {
    phaseBox.removeItemAt(phaseBox.getItemCount() - 1);
voidsetColorMenu(JComboBox choice)
set Color Menu
choice.addItem("BLACK");
choice.addItem("WHITE");
choice.addItem("RED");
choice.addItem("YELLOW");
choice.addItem("GREEN");
choice.addItem("CYAN");
choice.addItem("DARKGRAY");
choice.addItem("LIGHTGRAY");
...
voidsetComboBoxTheme(JComboBox comboBox)
set Combo Box Theme
comboBox.setEditable(true);
((JTextField) comboBox.getEditor().getEditorComponent()).setEditable(false);
voidsetErrorBackground(JComboBox comp)
set Error Background
comp.setBackground(ERROR_BACKGROUND);
voidsetJComboBoxAsHeavyweight(JComboBox combo)
set J Combo Box As Heavyweight
try {
    Class cls = Class.forName("javax.swing.PopupFactory");
    Field field = cls.getDeclaredField("forceHeavyWeightPopupKey");
    if (field != null) {
        field.setAccessible(true);
        combo.putClientProperty(field.get(null), Boolean.TRUE);
} catch (Exception e1) {
...
voidsetPopupComboChoices(JComboBox aComboBox, String aS)
Routine to strip all possible choices from a "popup" string

Example of a popup string: "file|socket|ethernet;socket"
The | splitted values are the possible combochoices
The ; splitted value is the default choice.
aComboBox.removeAllItems();
if (aS.length() < 1) {
    return;
String[] stripped = aS.split("\\;");
String defaultChoice = "";
if (stripped.length > 1) {
    defaultChoice = stripped[1];
...
voidsetShouldUseAlternSdk(boolean shouldUse, final JCheckBox useAlternativeSdkCB, final JComboBox alternativeSdksComboBox, final JComboBox myModulesComboBox)
set Should Use Altern Sdk
useAlternativeSdkCB.setSelected(shouldUse);
myModulesComboBox.setEnabled(!shouldUse);
alternativeSdksComboBox.setEnabled(shouldUse);