本文整理汇总了Java中javax.swing.JComboBox.getModel方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.getModel方法的具体用法?Java JComboBox.getModel怎么用?Java JComboBox.getModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JComboBox
的用法示例。
在下文中一共展示了JComboBox.getModel方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addToModel
import javax.swing.JComboBox; //导入方法依赖的package包/类
private void addToModel (final Revision newItem, final JComboBox cmbDiffTree) {
DefaultComboBoxModel model = (DefaultComboBoxModel) cmbDiffTree.getModel();
for (int i = 0; i < model.getSize(); ++i) {
final Object item = model.getElementAt(i);
if (item instanceof Revision && ((Revision) item).getCommitId().equals(newItem.getCommitId())
&& ((Revision) item).getRevision().equals(newItem.getRevision())) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run () {
cmbDiffTree.setSelectedItem(item);
}
});
return;
}
}
model.addElement(newItem);
EventQueue.invokeLater(new Runnable() {
@Override
public void run () {
cmbDiffTree.setSelectedItem(newItem);
}
});
}
示例2: selectInCombo
import javax.swing.JComboBox; //导入方法依赖的package包/类
private boolean selectInCombo(JComboBox combo, Object value, boolean forceInModel) {
if (value == null) {
return false;
}
if (!value.equals(combo.getSelectedItem())) {
combo.setSelectedItem(value);
}
if (forceInModel && !value.equals("") && !value.equals(combo.getSelectedItem())) { // NOI18N
// Reload of server attributes is needed - workarounding it
ComboBoxModel model = combo.getModel();
if (model instanceof DefaultComboBoxModel) {
((DefaultComboBoxModel)model).insertElementAt(value, 0);
combo.setSelectedIndex(0);
}
}
return value.equals(combo.getSelectedItem());
}
示例3: assertModel
import javax.swing.JComboBox; //导入方法依赖的package包/类
private void assertModel (Map<String, String> items, JComboBox combo, List<String> expected) {
ComboBoxModel model = combo.getModel();
assertEquals(expected.size() / 2, model.getSize());
for (int i = 0; i < model.getSize(); ++i) {
assertEquals(expected.get(i * 2), model.getElementAt(i));
assertEquals(expected.get(i * 2 + 1), items.get((String) model.getElementAt(i)));
}
}
示例4: performBrowseType
import javax.swing.JComboBox; //导入方法依赖的package包/类
private static void performBrowseType(final JComboBox combo, final ClasspathInfo cpInfo) {
final ReturnTypeComboBoxModel model = (ReturnTypeComboBoxModel) combo.getModel();
combo.setPopupVisible(false);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final ElementHandle<TypeElement> handle = TypeElementFinder.find(cpInfo, new TypeElementFinder.Customizer() {
public Set<ElementHandle<TypeElement>> query(ClasspathInfo classpathInfo, String textForQuery, NameKind nameKind, Set<SearchScope> searchScopes) {//GEN-LAST:event_browseButtonActionPerformed
return classpathInfo.getClassIndex().getDeclaredTypes(textForQuery, nameKind, searchScopes);
}
public boolean accept(ElementHandle<TypeElement> typeHandle) {
return true;
}
});
combo.setPopupVisible(false);
if (handle == null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setSelectedItem(combo, model.getPreviousItem());
}
});
} else {
setSelectedItem(combo, handle.getQualifiedName());
}
}
});
}
示例5: findInModel
import javax.swing.JComboBox; //导入方法依赖的package包/类
private String findInModel(JComboBox combo, String value) {
ComboBoxModel model = combo.getModel();
for(int i = 0; i < model.getSize(); i++) {
String element = model.getElementAt(i).toString();
if(value.toLowerCase().equals(element.toString().toLowerCase())) {
return element;
}
}
return null;
}
示例6: getRendererComponent
import javax.swing.JComboBox; //导入方法依赖的package包/类
private static Component getRendererComponent(JComboBox comboBox, int option) {
ComboBoxModel model = comboBox.getModel();
if (option >= model.getSize()) {
throw new NoSuchElementException("Index out-of-bounds error on JComboBox: " + option, null);
}
Component rendererComponent = comboBox.getRenderer().getListCellRendererComponent(new JList(model),
model.getElementAt(option), option, false, false);
return rendererComponent;
}
示例7: checkOldComboBoxModel
import javax.swing.JComboBox; //导入方法依赖的package包/类
private void checkOldComboBoxModel(JComboBox comboBox) {
ComboBoxModel oldModel = comboBox.getModel();
if ((oldModel != null) && (oldModel.getSize() != 0)) {
throw new IllegalStateException("The combo-box must be empty."); //NOI18N
}
}
示例8: prepareCombo
import javax.swing.JComboBox; //导入方法依赖的package包/类
protected void prepareCombo(JComboBox combo, int row, int column){
Feature feature = featureList.get(row);
DefaultComboBoxModel comboModel = (DefaultComboBoxModel)combo.getModel();
comboModel.removeAllElements();
switch(column){
case NAME_COL:
List<String> fNames = new ArrayList<String>();
if(schema != null && schema.getFeatureSchemaSet() != null){
Iterator<FeatureSchema> fSchemaIter = schema.getFeatureSchemaSet().iterator();
while(fSchemaIter.hasNext())
fNames.add(fSchemaIter.next().getFeatureName());
}
if(!fNames.contains(feature.name))fNames.add(feature.name);
Collections.sort(fNames);
for(Iterator<String> nameIter = fNames.iterator();
nameIter.hasNext();
comboModel.addElement(nameIter.next()));
combo.getEditor().getEditorComponent().setBackground(defaultBackground);
combo.setSelectedItem(feature.name);
break;
case VALUE_COL:
List<Object> fValues = new ArrayList<Object>();
if(feature.isSchemaFeature()){
Set<Object> permValues = schema.getFeatureSchema(feature.name).
getPermittedValues();
if(permValues != null) fValues.addAll(permValues);
}
if(!fValues.contains(feature.value)) fValues.add(feature.value);
Collections.sort(fValues, defaultComparator);
for(Iterator<Object> valIter = fValues.iterator();
valIter.hasNext();
comboModel.addElement(valIter.next()));
combo.getEditor().getEditorComponent().setBackground(feature.isCorrect() ?
defaultBackground :
(feature.isRequired() ? REQUIRED_WRONG : OPTIONAL_WRONG));
combo.setSelectedItem(feature.value);
break;
default: ;
}
}