Example usage for javax.swing DefaultComboBoxModel getIndexOf

List of usage examples for javax.swing DefaultComboBoxModel getIndexOf

Introduction

In this page you can find the example usage for javax.swing DefaultComboBoxModel getIndexOf.

Prototype

public int getIndexOf(Object anObject) 

Source Link

Document

Returns the index-position of the specified object in the list.

Usage

From source file:shuffle.fwk.gui.EffectChooser.java

public void setSelectedEffect(Effect effect) {
    String toSelect = null;// w w  w. j a v  a  2s  .  c  om
    if (effect != null) {
        if (shouldRebuild) {
            refill();
        }
        toSelect = convertToBox(effect.toString());
        DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) getModel();
        if (model.getIndexOf(toSelect) == -1) {
            shouldRebuild = true;
            insertItemAt(toSelect, 0);
        } else {
            shouldRebuild = false;
        }
    }
    setSelectedItem(toSelect);
}

From source file:shuffle.fwk.gui.TypeChooser.java

public void setSelectedType(PkmType type) {
    String toSelect = null;/*from   ww  w . j av a 2 s  .  c  o m*/
    if (type != null) {
        if (shouldRebuild) {
            refill();
        }
        toSelect = WordUtils.capitalizeFully(type.toString());
        DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) getModel();
        if (model.getIndexOf(toSelect) == -1) {
            shouldRebuild = true;
            insertItemAt(toSelect, 0);
        } else {
            shouldRebuild = false;
        }
    }
    setSelectedItem(toSelect);
}