下面列出了javax.swing.JComboBox#setPopupVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JComboBox) {
JComboBox combo = (JComboBox) e.getSource();
combo.setPopupVisible(!combo.isPopupVisible());
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JComboBox) {
JComboBox combo = (JComboBox) e.getSource();
combo.setPopupVisible(!combo.isPopupVisible());
}
}
@Override
public void actionPerformed(ActionEvent e) {
final JComboBox comboBox = (JComboBox)e.getSource();
Object selectedItem = comboBox.getSelectedItem();
if (selectedItem == NEW_ITEM) {
performingNewItemAction = true;
try {
comboBox.setPopupVisible(false);
dataModel.newItemActionPerformed();
} finally {
performingNewItemAction = false;
}
setPreviousNonSpecialItem(comboBox);
// we (or maybe the client) have just selected an item inside an actionPerformed event,
// which will not send another actionPerformed event for the new item.
// We need to make sure all listeners get an event for the new item,
// thus...
final Object newSelectedItem = comboBox.getSelectedItem();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
comboBox.setSelectedItem(newSelectedItem);
}
});
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JComboBox) {
JComboBox combo = (JComboBox) e.getSource();
combo.setPopupVisible(!combo.isPopupVisible());
}
}
public void actionPerformed(ActionEvent e) {
if( e.getSource() instanceof JComboBox ) {
JComboBox combo = (JComboBox)e.getSource();
combo.setPopupVisible( !combo.isPopupVisible() );
}
}
public void actionPerformed(ActionEvent e) {
if( e.getSource() instanceof JComboBox ) {
JComboBox combo = (JComboBox)e.getSource();
combo.setPopupVisible( !combo.isPopupVisible() );
}
}
/**
* Enables automatic completion for the given JComboBox. The automatic
* completion will be strict (only items from the combo box can be selected)
* if the combo box is not editable.
* @param comboBox a combo box
* @param stringConverter the converter used to transform items to strings
*/
public static void decorate(final JComboBox comboBox, final ObjectToStringConverter stringConverter) {
boolean strictMatching = !comboBox.isEditable();
// has to be editable
comboBox.setEditable(true);
// fix the popup location
AquaLnFPopupLocationFix.install(comboBox);
// configure the text component=editor component
JTextComponent editorComponent = (JTextComponent) comboBox.getEditor().getEditorComponent();
final AbstractAutoCompleteAdaptor adaptor = new ComboBoxAdaptor(comboBox);
final AutoCompleteDocument document = new AutoCompleteDocument(adaptor, strictMatching, stringConverter);
decorate(editorComponent, document, adaptor);
// show the popup list when the user presses a key
final KeyListener keyListener = new KeyAdapter() {
public void keyPressed(KeyEvent keyEvent) {
// don't popup on action keys (cursor movements, etc...)
if (keyEvent.isActionKey()) return;
// don't popup if the combobox isn't visible anyway
if (comboBox.isDisplayable() && !comboBox.isPopupVisible()) {
int keyCode = keyEvent.getKeyCode();
// don't popup when the user hits shift,ctrl or alt
if (keyCode==keyEvent.VK_SHIFT || keyCode==keyEvent.VK_CONTROL || keyCode==keyEvent.VK_ALT) return;
// don't popup when the user hits escape (see issue #311)
if (keyCode==keyEvent.VK_ESCAPE) return;
comboBox.setPopupVisible(true);
}
}
};
editorComponent.addKeyListener(keyListener);
if (stringConverter!=ObjectToStringConverter.DEFAULT_IMPLEMENTATION) {
comboBox.setEditor(new AutoCompleteComboBoxEditor(comboBox.getEditor(), stringConverter));
}
// Changing the l&f can change the combobox' editor which in turn
// would not be autocompletion-enabled. The new editor needs to be set-up.
comboBox.addPropertyChangeListener("editor", new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
ComboBoxEditor 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);
}
}
}
});
}