javax.swing.JComboBox.setEditor()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中javax.swing.JComboBox.setEditor()方法的一些代码示例,展示了JComboBox.setEditor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.setEditor()方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:setEditor

JComboBox.setEditor介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javafx2-project

public void setEditor(ComboBoxEditor anEditor) {
  combo.setEditor(anEditor);
}

代码示例来源:origin: com.anrisoftware.prefdialog/prefdialog-misc-swing

/**
 * Decorates the combo-box as a validating combo-box field.
 * 
 * @param field
 *            the {@link JComboBox}.
 * 
 * @return the {@link ValidatingComboBoxEditor} editor.
 */
public static ValidatingComboBoxEditor decorate(JComboBox<?> field) {
  ValidatingComboBoxEditor editor = new ValidatingComboBoxEditor();
  field.setEditor(editor);
  return editor;
}

代码示例来源:origin: notzippy/JALOPY2-MAIN

/**
   * DOCUMENT ME!
   */
  private void initialize()
  {
    JComboBox combo = getComboBox();
    combo.setEditor(
      new NumberComboBoxEditor(
        Integer.parseInt((String) combo.getSelectedItem()), 3));
    combo.setEditable(true);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mercurial

private void tweakComboBoxEditor() {
  final ComboBoxEditor origEditor = repositoryPanel.urlComboBox.getEditor();
  if (origEditor.getClass() == UrlComboBoxEditor.class) {
    /* attempt to tweak the combo-box multiple times */
    assert false;
    return;
  }
  repositoryPanel.urlComboBox.setEditor(new UrlComboBoxEditor(origEditor));
}

代码示例来源:origin: sdedit/sdedit

private void initialize() {
  comboBox = new JComboBox();
  if (this.comboBoxEditable) {
    comboBox.setEditable(true);
    AutoCompletionComboboxEditor editor = new AutoCompletionComboboxEditor(comboBox);	
    comboBox.setEditor(editor);
  } else {
    comboBox.setEditable(false);
  }
  comboBox.setRenderer(this);
  ToolTipManager.sharedInstance().registerComponent(comboBox);
  comboBox.addActionListener(this);
  getBottomPanel().setLayout(new BorderLayout());
  getBottomPanel().add(comboBox, BorderLayout.CENTER);
  reinitialize(true);
}

代码示例来源:origin: org.bitbucket.goalhub.simpleide/jedit

/**
 * Adds a file filter to the browser.
 *
 * @since jEdit 4.3pre7
 */
public void addVFSFileFilter(VFSFileFilter filter)
{
  filterField.addItem(filter);
  if (filterField.getItemCount() == 2)
  {
    filterField.setEditor(filterEditor);
    filterField.setEditable(true);
    GridBagLayout layout = (GridBagLayout) pathAndFilterPanel.getLayout();
    GridBagConstraints cons =layout.getConstraints(filterEditor);
    cons.gridwidth = GridBagConstraints.REMAINDER;
    cons.fill = GridBagConstraints.HORIZONTAL;
    cons.gridx = 1;
    cons.weightx = 1;
    pathAndFilterPanel.remove(filterEditor);
    layout.setConstraints(filterField, cons);
    pathAndFilterPanel.add(filterField);
    pathAndFilterPanel.validate();
    pathAndFilterPanel.repaint();
  }
} //}}}

代码示例来源:origin: com.anrisoftware.prefdialog/prefdialog-corefields

/**
 * Sets the specified editor for the combo box field.
 * 
 * @param editor
 *            the {@link ComboBoxEditor}.
 * 
 * @throws NullPointerException
 *             if the specified editor is {@code null}.
 */
public void setEditor(ComboBoxEditor editor) {
  log.checkEditor(this, editor);
  getComponent().setEditor(editor);
  log.editorSet(this, editor);
}

代码示例来源:origin: freeplane/freeplane

public Container createSizeBox() {
  final JComboBox sizeBox = new JComboBoxWithBorder(size);
  sizeBox.setPrototypeDisplayValue("88888");
  sizeBox.setPreferredSize(sizeBox.getPreferredSize());
  sizeBox.setEditor(new FixedBasicComboBoxEditor());
  sizeBox.setEditable(true);
  return sizeBox;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-bugtracking

public QuickSearchComboBar(JComponent caller) {
  this.caller = caller;
  initComponents();
  command.setRenderer(new DefaultListCellRenderer() {
    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      if(value instanceof IssueImpl) {
        IssueImpl item = (IssueImpl) value;
        value = IssueItem.getIssueDescription(item);
      }
      return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    }
  });
  command.setEditor(new ComboEditor(command.getEditor()));
  displayer = new QuickSearchPopup(this);
}

代码示例来源:origin: org.activecomponents.jadex/jadex-commons-gui

/**
   * 
   */
  public void setEditor(ComboBoxEditor anEditor)
  {
    super.setEditor(anEditor);
    JTextComponent comp = (JTextComponent)getEditor().getEditorComponent();
    if(comp.getDocument() instanceof AutoCompleteCombo.AutoCompleteDocument)
    {
      AutoCompleteCombo.AutoCompleteDocument doc = (AutoCompleteCombo.AutoCompleteDocument)comp.getDocument();
      doc.dispose();
    }
    comp.setDocument(new AutoCompleteDocument());
  }
//

代码示例来源:origin: net.java.truecommons/truecommons-key-swing

private void changeComboBox(
    final @Nullable JComboBox<E> oldCB,
    final @Nullable JComboBox<E> newCB,
    final boolean update) {
  if (newCB == oldCB) return;
  ComboBoxEditor oldCBE = null;
  if (null != oldCB) {
    oldCB.removePropertyChangeListener("editor", listener);
    oldCBE = oldCB.getEditor();
    oldCB.setEditor(((AbstractComboBoxBrowser<?>.DecoratingComboBoxEditor) oldCBE).getEditor());
  }
  this.comboBox = newCB;
  ComboBoxEditor newCBE = null;
  if (null != newCB) {
    newCB.updateUI(); // ensure comboBoxEditor is initialized
    newCBE = new DecoratingComboBoxEditor(newCB.getEditor());
    newCB.setEditor(newCBE);
    newCB.addPropertyChangeListener("editor", listener);
  }
  changeEditor(oldCBE, newCBE, update);
}

代码示例来源:origin: freeplane/freeplane

private void setValuesEditor() {
  final Object selectedProperty = filteredPropertiesComponent.getSelectedItem();
  final IElementaryConditionController conditionController = filterController.getConditionFactory()
    .getConditionController(selectedProperty);
  final TranslatedObject selectedCondition = (TranslatedObject) elementaryConditions.getSelectedItem();
  final boolean canSelectValues = conditionController
    .canSelectValues(selectedProperty, selectedCondition);
  values.setEnabled(canSelectValues);
  values.setEditable(false);
  values.setModel(conditionController.getValuesForProperty(selectedProperty, selectedCondition));
  final ComboBoxEditor valueEditor = conditionController.getValueEditor(selectedProperty, selectedCondition);
  values.setEditor(valueEditor != null ? valueEditor : new FixedBasicComboBoxEditor());
  setValuesEnterKeyListener();
  final ListCellRenderer valueRenderer = conditionController.getValueRenderer(selectedProperty, selectedCondition);
  values.setRenderer(valueRenderer != null ? valueRenderer : filterController.getConditionRenderer());
  values.setEditable(conditionController.canEditValues(selectedProperty, selectedCondition));
  if (values.getModel().getSize() > 0) {
    values.setSelectedIndex(0);
  }
  caseSensitive.setEnabled(canSelectValues
      && conditionController.isCaseDependent(selectedProperty, selectedCondition));
  approximateMatching.setEnabled(canSelectValues
      && conditionController.supportsApproximateMatching(selectedProperty, selectedCondition));
}
/**

代码示例来源:origin: net.java.truevfs/truevfs-key-swing

private void changeComboBox(
    final @CheckForNull JComboBox<E> oldCB,
    final @CheckForNull JComboBox<E> newCB,
    final boolean update) {
  if (newCB == oldCB)
    return;
  ComboBoxEditor oldCBE = null;
  if (null != oldCB) {
    oldCB.removePropertyChangeListener("editor", listener);
    oldCBE = oldCB.getEditor();
    oldCB.setEditor(((AbstractComboBoxBrowser<?>.DecoratingComboBoxEditor) oldCBE).getEditor());
  }
  this.comboBox = newCB;
  ComboBoxEditor newCBE = null;
  if (null != newCB) {
    newCB.updateUI(); // ensure comboBoxEditor is initialized
    newCBE = new DecoratingComboBoxEditor(newCB.getEditor());
    newCB.setEditor(newCBE);
    newCB.addPropertyChangeListener("editor", listener);
  }
  changeEditor(oldCBE, newCBE, update);
}

代码示例来源:origin: de.schlichtherle.truezip/truezip-swing

private void changeComboBox(
    final @CheckForNull JComboBox<E> oldCB,
    final @CheckForNull JComboBox<E> newCB,
    final boolean update) {
  if (newCB == oldCB)
    return;
  ComboBoxEditor oldCBE = null;
  if (null != oldCB) {
    oldCB.removePropertyChangeListener("editor", listener);
    oldCBE = oldCB.getEditor();
    oldCB.setEditor(((AbstractComboBoxBrowser<?>.DecoratingComboBoxEditor) oldCBE).getEditor());
  }
  this.comboBox = newCB;
  ComboBoxEditor newCBE = null;
  if (null != newCB) {
    newCB.updateUI(); // ensure comboBoxEditor is initialized
    newCBE = new DecoratingComboBoxEditor(newCB.getEditor());
    newCB.setEditor(newCBE);
    newCB.addPropertyChangeListener("editor", listener);
  }
  changeEditor(oldCBE, newCBE, update);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-lib-profiler-ui

public Dimension getPreferredSize() {
  Dimension dim = super.getPreferredSize();
  if (preferredHeight == -1) {
    JToolBar tb = new JToolBar();
    tb.setBorder(toolbar.getBorder());
    tb.setBorderPainted(toolbar.isBorderPainted());
    tb.setRollover(toolbar.isRollover());
    tb.setFloatable(toolbar.isFloatable());
    Icon icon = Icons.getIcon(GeneralIcons.SAVE);
    JButton b = new JButton("Button", icon); // NOI18N
    tb.add(b);
    JToggleButton t = new JToggleButton("Button", icon); // NOI18N
    tb.add(t);
    JComboBox c = new JComboBox();
    c.setEditor(new BasicComboBoxEditor());
    c.setRenderer(new BasicComboBoxRenderer());
    tb.add(c);
    tb.addSeparator();
    preferredHeight = tb.getPreferredSize().height;
  }
  dim.height = Math.max(dim.height, preferredHeight);
  return dim;
}
public void doLayout() {

代码示例来源:origin: Multibit-Legacy/multibit-hd

/**
 * @param contactService    The contact service
 * @param networkParameters The Bitcoin network parameters
 *
 * @return A new "recipient" combo box with auto-complete functionality
 */
public static JComboBox<Recipient> newRecipientComboBox(ContactService contactService, NetworkParameters networkParameters) {
 Preconditions.checkNotNull(contactService, "'contactService' must be present");
 Preconditions.checkNotNull(networkParameters, "'networkParameters' must be present");
 AutoCompleteFilter<Recipient> filter = AutoCompleteFilters.newRecipientFilter(contactService);
 JComboBox<Recipient> comboBox = newComboBox(filter.create());
 // Ensure it is accessible
 AccessibilityDecorator.apply(comboBox, MessageKey.RECIPIENT, MessageKey.RECIPIENT_TOOLTIP);
 // Remove border
 comboBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
 // Ensure we start with nothing selected (must come before editor is set)
 comboBox.setSelectedIndex(-1);
 // Allow editing
 comboBox.setEditable(true);
 // Use a recipient editor to force use of the name field
 comboBox.setEditor(new RecipientComboBoxEditor(contactService, networkParameters));
 // Use a recipient list cell renderer to ensure recipient is set on selection
 JTextField textField = (JTextField) comboBox.getEditor().getEditorComponent();
 ListCellRenderer<Recipient> renderer = new RecipientListCellRenderer(textField);
 AccessibilityDecorator.apply(textField, MessageKey.RECIPIENT, MessageKey.RECIPIENT_TOOLTIP);
 comboBox.setRenderer(renderer);
 AutoCompleteDecorator.apply(comboBox, filter);
 return comboBox;
}

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

public void propertyChange(PropertyChangeEvent e) {
    ComboBoxEditor editor = (ComboBoxEditor) e.getOldValue();
    if (editor != null && editor.getEditorComponent() != null) {
      removeKeyListener(editor.getEditorComponent());
    }
    
     editor = (ComboBoxEditor) e.getNewValue();
     if (editor!=null && editor.getEditorComponent()!=null) {
      if (!(editor instanceof AutoCompleteComboBoxEditor) 
        && stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) {
        comboBox.setEditor(new AutoCompleteComboBoxEditor(editor, stringConverter));
        // Don't do the decorate step here because calling setEditor will trigger
        // the propertychange listener a second time, which will do the decorate
        // and addKeyListener step.
      } else {
        decorate((JTextComponent) editor.getEditorComponent(), document, adaptor);
        editor.getEditorComponent().addKeyListener(keyListener);
      }
     }
  }
});

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private LocalServerController(JComboBox<LocalServer> localServerComboBox, JButton localServerBrowseButton,
    SourcesFolderProvider sourcesFolderProvider, BrowseHandler browseHandler, String browseDialogTitle, LocalServer... defaultLocalServers) {
  assert localServerComboBox != null;
  assert localServerBrowseButton != null;
  assert browseHandler != null;
  assert browseDialogTitle != null;
  assert localServerComboBox.isEditable() : "localServerComboBox has to be editable";
  assert localServerComboBox.getEditor().getEditorComponent() instanceof JTextField;
  this.localServerComboBox = localServerComboBox;
  this.localServerBrowseButton = localServerBrowseButton;
  this.sourcesFolderProvider = sourcesFolderProvider;
  this.browseHandler = browseHandler;
  this.browseDialogTitle = browseDialogTitle;
  localServerComboBoxModel = new LocalServer.ComboBoxModel(defaultLocalServers);
  JTextField editor = (JTextField) localServerComboBox.getEditor().getEditorComponent();
  localServerComboBoxEditor = new LocalServer.ComboBoxEditor(editor);
  localServerComboBox.setModel(localServerComboBoxModel);
  localServerComboBox.setRenderer(new LocalServer.ComboBoxRenderer());
  localServerComboBox.setEditor(localServerComboBoxEditor);
  registerListeners();
}

代码示例来源:origin: org.swinglabs.swingx/swingx-all

comboBox.setEditor(new AutoCompleteComboBoxEditor(comboBox.getEditor(), document.stringConverter));

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

/**
 * Enables auto-completion for specified combobox
 *
 * @param comboBox Combo to be featured
 * @param strict Whether strict matching (check 'startWith' or 'contains') should be used
 * @param allowsUserValues Whether non-present items are allowed 
 */
public static void enable(JComboBox comboBox, boolean strict, boolean allowsUserValues) {
  comboBox.setEditable(true);
  KeyListener[] listeners = comboBox.getEditor().getEditorComponent().getListeners(KeyListener.class);
  comboBox.setEditor(new CustomTypeComboBoxEditor(comboBox, allowsUserValues));
  for (KeyListener listener : listeners) {
    comboBox.getEditor().getEditorComponent().addKeyListener(listener);
  }
  AutoCompletion ac = new AutoCompletion(comboBox, strict, allowsUserValues);
  comboBox.addFocusListener(ac);
  ac.textEditor.addKeyListener(ac);
  //original keys would not work properly
  SwingUtilities.replaceUIActionMap(comboBox, null);
}

相关文章

JComboBox类方法