} } } /** * Sets the action command that should be included in the event * sent to action listeners. * * @param aCommand a string containing the "command" that is sent * to action listeners; the same listener can then * do different things depending on the command it * receives */ public void setActionCommand(String aCommand) { actionCommand = aCommand; } /** * Returns the action command that is included in the event sent to * action listeners. * * @return the string containing the "command" that is sent * to action listeners. */ public String getActionCommand() { return actionCommand; } private Action action; private PropertyChangeListener actionPropertyChangeListener; /** * Sets the <code>Action</code> for the <code>ActionEvent</code> source. * The new <code>Action</code> replaces any previously set * <code>Action</code> but does not affect <code>ActionListeners</code> * independently added with <code>addActionListener</code>. * If the <code>Action</code> is already a registered * <code>ActionListener</code> for the <code>ActionEvent</code> source, * it is not re-registered. * <p> * Setting the <code>Action</code> results in immediately changing * all the properties described in <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a>. * Subsequently, the combobox's properties are automatically updated * as the <code>Action</code>'s properties change. * <p> * This method uses three other methods to set * and help track the <code>Action</code>'s property values. * It uses the <code>configurePropertiesFromAction</code> method * to immediately change the combobox's properties. * To track changes in the <code>Action</code>'s property values, * this method registers the <code>PropertyChangeListener</code> * returned by <code>createActionPropertyChangeListener</code>. The * default {@code PropertyChangeListener} invokes the * {@code actionPropertyChanged} method when a property in the * {@code Action} changes. * * @param a the <code>Action</code> for the <code>JComboBox</code>, * or <code>null</code>. * @since 1.3 * @see Action * @see #getAction * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener * @see #actionPropertyChanged * @beaninfo * bound: true * attribute: visualUpdate true * description: the Action instance connected with this ActionEvent source */ public void setAction(Action a) { Action oldValue = getAction(); if (action==null || !action.equals(a)) { action = a; if (oldValue!=null) { removeActionListener(oldValue); oldValue.removePropertyChangeListener(actionPropertyChangeListener); actionPropertyChangeListener = null; } configurePropertiesFromAction(action); if (action!=null) { // Don't add if it is already a listener if (!isListener(ActionListener.class, action)) { addActionListener(action); } // Reverse linkage: actionPropertyChangeListener = createActionPropertyChangeListener(action); action.addPropertyChangeListener(actionPropertyChangeListener); } firePropertyChange("action", oldValue, action); } } private boolean isListener(Class c, ActionListener a) { boolean isListener = false; Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length-2; i>=0; i-=2) { if (listeners[i]==c && listeners[i+1]==a) { isListener=true; } } return isListener; } /** * Returns the currently set <code>Action</code> for this * <code>ActionEvent</code> source, or <code>null</code> if no * <code>Action</code> is set. * * @return the <code>Action</code> for this <code>ActionEvent</code> * source; or <code>null</code> * @since 1.3 * @see Action * @see #setAction */ public Action getAction() { return action; } /** * Sets the properties on this combobox to match those in the specified * <code>Action</code>. Refer to <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a> for more * details as to which properties this sets. * * @param a the <code>Action</code> from which to get the properties, * or <code>null</code> * @since 1.3 * @see Action * @see #setAction */ protected void configurePropertiesFromAction(Action a) { AbstractAction.setEnabledFromAction(this, a); AbstractAction.setToolTipTextFromAction(this, a); setActionCommandFromAction(a); } /** * Creates and returns a <code>PropertyChangeListener</code> that is * responsible for listening for changes from the specified * <code>Action</code> and updating the appropriate properties. * <p> * <b>Warning:</b> If you subclass this do not create an anonymous * inner class. If you do the lifetime of the combobox will be tied to * that of the <code>Action</code>. * * @param a the combobox's action * @since 1.3 * @see Action * @see #setAction */ protected PropertyChangeListener createActionPropertyChangeListener(Action a) { return new ComboBoxActionPropertyChangeListener(this, a); } /** * Updates the combobox's state in response to property changes in * associated action. This method is invoked from the * {@code PropertyChangeListener} returned from * {@code createActionPropertyChangeListener}. Subclasses do not normally * need to invoke this. Subclasses that support additional {@code Action} * properties should override this and * {@code configurePropertiesFromAction}. * <p> * Refer to the table at <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a> for a list of * the properties this method sets. * * @param action the <code>Action</code> associated with this combobox * @param propertyName the name of the property that changed * @since 1.6 * @see Action * @see #configurePropertiesFromAction */ protected void actionPropertyChanged(Action action, String propertyName) { if (propertyName == Action.ACTION_COMMAND_KEY) { setActionCommandFromAction(action); } else if (propertyName == "enabled") { AbstractAction.setEnabledFromAction(this, action); } else if (Action.SHORT_DESCRIPTION == propertyName) { AbstractAction.setToolTipTextFromAction(this, action); } } private void setActionCommandFromAction(Action a) { setActionCommand((a != null) ? (String)a.getValue(Action.ACTION_COMMAND_KEY) : null); } private static class ComboBoxActionPropertyChangeListener extends ActionPropertyChangeListener<JComboBox<?>> { ComboBoxActionPropertyChangeListener(JComboBox<?> b, Action a) { super(b, a); } protected void actionPropertyChanged(JComboBox<?> cb, Action action, PropertyChangeEvent e) { if (AbstractAction.shouldReconfigure(e)) { cb.configurePropertiesFromAction(action); } else { cb.actionPropertyChanged(action, e.getPropertyName()); } } } /** * Notifies all listeners that have registered interest for * notification on this event type. * @param e the event of interest * * @see EventListenerList */ protected void fireItemStateChanged(ItemEvent e) { // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event for ( int i = listeners.length-2; i>=0; i-=2 ) { if ( listeners[i]==ItemListener.class ) { // Lazily create the event: // if (changeEvent == null) // changeEvent = new ChangeEvent(this); ((ItemListener)listeners[i+1]).itemStateChanged(e); } } } /** * Notifies all listeners that have registered interest for * notification on this event type. * * @see EventListenerList */ protected void fireActionEvent() { if (!firingActionEvent) { // Set flag to ensure that an infinite loop is not created firingActionEvent = true; ActionEvent e = null; // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); long mostRecentEventTime = EventQueue.getMostRecentEventTime(); int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent)currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent)currentEvent).getModifiers(); } // Process the listeners last to first, notifying // those that are interested in this event for ( int i = listeners.length-2; i>=0; i-=2 ) { if ( listeners[i]==ActionListener.class ) { // Lazily create the event: if ( e == null ) e = new ActionEvent(this,ActionEvent.ACTION_PERFORMED, getActionCommand(), mostRecentEventTime, modifiers); ((ActionListener)listeners[i+1]).actionPerformed(e); } } firingActionEvent = false; } } /** * This protected method is implementation specific. Do not access directly * or override. */ protected void selectedItemChanged() { if (selectedItemReminder != null ) { fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED, selectedItemReminder, ItemEvent.DESELECTED)); } // set the new selected item. selectedItemReminder = dataModel.getSelectedItem(); if (selectedItemReminder != null ) { fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED, selectedItemReminder, ItemEvent.SELECTED)); } } /** * Returns an array containing the selected item. * This method is implemented for compatibility with * <code>ItemSelectable</code>. * * @return an array of <code>Objects</code> containing one * element -- the selected item */ public Object[] getSelectedObjects() { Object selectedObject = getSelectedItem(); if ( selectedObject == null ) return new Object[0]; else { Object result[] = new Object[1]; result[0] = selectedObject; return result; } } /** * This method is public as an implementation side effect. * do not call or override. */ public void actionPerformed(ActionEvent e) { Object newItem = getEditor().getItem(); setPopupVisible(false); getModel().setSelectedItem(newItem); String oldCommand = getActionCommand(); setActionCommand("comboBoxEdited"); fireActionEvent(); setActionCommand(oldCommand); } /** * This method is public as an implementation side effect. * do not call or override. */ public void contentsChanged(ListDataEvent e) { Object oldSelection = selectedItemReminder; Object newSelection = dataModel.getSelectedItem(); if (oldSelection == null || !oldSelection.equals(newSelection)) { selectedItemChanged(); if (!selectingItem) { fireActionEvent(); } } } /** * This method is public as an implementation side effect. * do not call or override. */ public void intervalAdded(ListDataEvent e) { if (selectedItemReminder != dataModel.getSelectedItem()) { selectedItemChanged(); } } /** * This method is public as an implementation side effect. * do not call or override. */ public void intervalRemoved(ListDataEvent e) { contentsChanged(e); } /** * Selects the list item that corresponds to the specified keyboard * character and returns true, if there is an item corresponding * to that character. Otherwise, returns false. * * @param keyChar a char, typically this is a keyboard key * typed by the user */ public boolean selectWithKeyChar(char keyChar) { int index; if ( keySelectionManager == null ) keySelectionManager = createDefaultKeySelectionManager(); index = keySelectionManager.selectionForKey(keyChar,getModel()); if ( index != -1 ) { setSelectedIndex(index); return true; } else return false; } /** * Enables the combo box so that items can be selected. When the * combo box is disabled, items cannot be selected and values * cannot be typed into its field (if it is editable). * * @param b a boolean value, where true enables the component and * false disables it * @beaninfo * bound: true * preferred: true * description: Whether the combo box is enabled. */ public void setEnabled(boolean b) { super.setEnabled(b); firePropertyChange( "enabled", !isEnabled(), isEnabled() ); } /** * Initializes the editor with the specified item. * * @param anEditor the <code>ComboBoxEditor</code> that displays * the list item in the * combo box field and allows it to be edited * @param anItem the object to display and edit in the field */ public void configureEditor(ComboBoxEditor anEditor, Object anItem) { anEditor.setItem(anItem); } /** * Handles <code>KeyEvent</code>s, looking for the Tab key. * If the Tab key is found, the popup window is closed. * * @param e the <code>KeyEvent</code> containing the keyboard * key that was pressed */ public void processKeyEvent(KeyEvent e) { if ( e.getKeyCode() == KeyEvent.VK_TAB ) { hidePopup(); } super.processKeyEvent(e); } /** * Sets the object that translates a keyboard character into a list * selection. Typically, the first selection with a matching first * character becomes the selected item. * * @beaninfo * expert: true * description: The objects that changes the selection when a key is pressed. */ public void setKeySelectionManager(KeySelectionManager aManager) { keySelectionManager = aManager; } /** * Returns the list's key-selection manager. * * @return the <code>KeySelectionManager</code> currently in use */ public KeySelectionManager getKeySelectionManager() { return keySelectionManager; } /* Accessing the model */ /** * Returns the number of items in the list. * * @return an integer equal to the number of items in the list */ public int getItemCount() { return dataModel.getSize(); } /** * Returns the list item at the specified index. If <code>index</code> * is out of range (less than zero or greater than or equal to size) * it will return <code>null</code>. * * @param index an integer indicating the list position, where the first * item starts at zero * @return the item at that list position; or * <code>null</code> if out of range */ public E getItemAt(int index) { return dataModel.getElementAt(index); } /** * Returns an instance of the default key-selection manager. * * @return the <code>KeySelectionManager</code> currently used by the list * @see #setKeySelectionManager */ protected KeySelectionManager createDefaultKeySelectionManager() { return new DefaultKeySelectionManager(); } /** * The interface that defines a <code>KeySelectionManager</code>. * To qualify as a <code>KeySelectionManager</code>, * the class needs to implement the method * that identifies the list index given a character and the * combo box data model. */ public interface KeySelectionManager { /** Given <code>aKey</code> and the model, returns the row * that should become selected. Return -1 if no match was * found. * * @param aKey a char value, usually indicating a keyboard key that * was pressed * @param aModel a ComboBoxModel -- the component's data model, containing * the list of selectable items * @return an int equal to the selected row, where 0 is the * first item and -1 is none. */ int selectionForKey(char aKey,ComboBoxModel aModel); } class DefaultKeySelectionManager implements KeySelectionManager, Serializable { public int selectionForKey(char aKey,ComboBoxModel aModel) {Lines 1001–1500 of 2412. Previous lines Load more
} } } /** * Sets the action command that should be included in the event * sent to action listeners. * * @param aCommand a string containing the "command" that is sent * to action listeners; the same listener can then * do different things depending on the command it * receives */ public void setActionCommand(String aCommand) { actionCommand = aCommand; } /** * Returns the action command that is included in the event sent to * action listeners. * * @return the string containing the "command" that is sent * to action listeners. */ public String getActionCommand() { return actionCommand; } private Action action; private PropertyChangeListener actionPropertyChangeListener; /** * Sets the <code>Action</code> for the <code>ActionEvent</code> source. * The new <code>Action</code> replaces any previously set * <code>Action</code> but does not affect <code>ActionListeners</code> * independently added with <code>addActionListener</code>. * If the <code>Action</code> is already a registered * <code>ActionListener</code> for the <code>ActionEvent</code> source, * it is not re-registered. * <p> * Setting the <code>Action</code> results in immediately changing * all the properties described in <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a>. * Subsequently, the combobox's properties are automatically updated * as the <code>Action</code>'s properties change. * <p> * This method uses three other methods to set * and help track the <code>Action</code>'s property values. * It uses the <code>configurePropertiesFromAction</code> method * to immediately change the combobox's properties. * To track changes in the <code>Action</code>'s property values, * this method registers the <code>PropertyChangeListener</code> * returned by <code>createActionPropertyChangeListener</code>. The * default {@code PropertyChangeListener} invokes the * {@code actionPropertyChanged} method when a property in the * {@code Action} changes. * * @param a the <code>Action</code> for the <code>JComboBox</code>, * or <code>null</code>. * @since 1.3 * @see Action * @see #getAction * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener * @see #actionPropertyChanged * @beaninfo * bound: true * attribute: visualUpdate true * description: the Action instance connected with this ActionEvent source */ public void setAction(Action a) { Action oldValue = getAction(); if (action==null || !action.equals(a)) { action = a; if (oldValue!=null) { removeActionListener(oldValue); oldValue.removePropertyChangeListener(actionPropertyChangeListener); actionPropertyChangeListener = null; } configurePropertiesFromAction(action); if (action!=null) { // Don't add if it is already a listener if (!isListener(ActionListener.class, action)) { addActionListener(action); } // Reverse linkage: actionPropertyChangeListener = createActionPropertyChangeListener(action); action.addPropertyChangeListener(actionPropertyChangeListener); } firePropertyChange("action", oldValue, action); } } private boolean isListener(Class c, ActionListener a) { boolean isListener = false; Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length-2; i>=0; i-=2) { if (listeners[i]==c && listeners[i+1]==a) { isListener=true; } } return isListener; } /** * Returns the currently set <code>Action</code> for this * <code>ActionEvent</code> source, or <code>null</code> if no * <code>Action</code> is set. * * @return the <code>Action</code> for this <code>ActionEvent</code> * source; or <code>null</code> * @since 1.3 * @see Action * @see #setAction */ public Action getAction() { return action; } /** * Sets the properties on this combobox to match those in the specified * <code>Action</code>. Refer to <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a> for more * details as to which properties this sets. * * @param a the <code>Action</code> from which to get the properties, * or <code>null</code> * @since 1.3 * @see Action * @see #setAction */ protected void configurePropertiesFromAction(Action a) { AbstractAction.setEnabledFromAction(this, a); AbstractAction.setToolTipTextFromAction(this, a); setActionCommandFromAction(a); } /** * Creates and returns a <code>PropertyChangeListener</code> that is * responsible for listening for changes from the specified * <code>Action</code> and updating the appropriate properties. * <p> * <b>Warning:</b> If you subclass this do not create an anonymous * inner class. If you do the lifetime of the combobox will be tied to * that of the <code>Action</code>. * * @param a the combobox's action * @since 1.3 * @see Action * @see #setAction */ protected PropertyChangeListener createActionPropertyChangeListener(Action a) { return new ComboBoxActionPropertyChangeListener(this, a); } /** * Updates the combobox's state in response to property changes in * associated action. This method is invoked from the * {@code PropertyChangeListener} returned from * {@code createActionPropertyChangeListener}. Subclasses do not normally * need to invoke this. Subclasses that support additional {@code Action} * properties should override this and * {@code configurePropertiesFromAction}. * <p> * Refer to the table at <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a> for a list of * the properties this method sets. * * @param action the <code>Action</code> associated with this combobox * @param propertyName the name of the property that changed * @since 1.6 * @see Action * @see #configurePropertiesFromAction */ protected void actionPropertyChanged(Action action, String propertyName) { if (propertyName == Action.ACTION_COMMAND_KEY) { setActionCommandFromAction(action); } else if (propertyName == "enabled") { AbstractAction.setEnabledFromAction(this, action); } else if (Action.SHORT_DESCRIPTION == propertyName) { AbstractAction.setToolTipTextFromAction(this, action); } } private void setActionCommandFromAction(Action a) { setActionCommand((a != null) ? (String)a.getValue(Action.ACTION_COMMAND_KEY) : null); } private static class ComboBoxActionPropertyChangeListener extends ActionPropertyChangeListener<JComboBox<?>> { ComboBoxActionPropertyChangeListener(JComboBox<?> b, Action a) { super(b, a); } protected void actionPropertyChanged(JComboBox<?> cb, Action action, PropertyChangeEvent e) { if (AbstractAction.shouldReconfigure(e)) { cb.configurePropertiesFromAction(action); } else { cb.actionPropertyChanged(action, e.getPropertyName()); } } } /** * Notifies all listeners that have registered interest for * notification on this event type. * @param e the event of interest * * @see EventListenerList */ protected void fireItemStateChanged(ItemEvent e) { // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); // Process the listeners last to first, notifying // those that are interested in this event for ( int i = listeners.length-2; i>=0; i-=2 ) { if ( listeners[i]==ItemListener.class ) { // Lazily create the event: // if (changeEvent == null) // changeEvent = new ChangeEvent(this); ((ItemListener)listeners[i+1]).itemStateChanged(e); } } } /** * Notifies all listeners that have registered interest for * notification on this event type. * * @see EventListenerList */ protected void fireActionEvent() { if (!firingActionEvent) { // Set flag to ensure that an infinite loop is not created firingActionEvent = true; ActionEvent e = null; // Guaranteed to return a non-null array Object[] listeners = listenerList.getListenerList(); long mostRecentEventTime = EventQueue.getMostRecentEventTime(); int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent)currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent)currentEvent).getModifiers(); } // Process the listeners last to first, notifying // those that are interested in this event for ( int i = listeners.length-2; i>=0; i-=2 ) { if ( listeners[i]==ActionListener.class ) { // Lazily create the event: if ( e == null ) e = new ActionEvent(this,ActionEvent.ACTION_PERFORMED, getActionCommand(), mostRecentEventTime, modifiers); ((ActionListener)listeners[i+1]).actionPerformed(e); } } firingActionEvent = false; } } /** * This protected method is implementation specific. Do not access directly * or override. */ protected void selectedItemChanged() { if (selectedItemReminder != null ) { fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED, selectedItemReminder, ItemEvent.DESELECTED)); } // set the new selected item. selectedItemReminder = dataModel.getSelectedItem(); if (selectedItemReminder != null ) { fireItemStateChanged(new ItemEvent(this,ItemEvent.ITEM_STATE_CHANGED, selectedItemReminder, ItemEvent.SELECTED)); } } /** * Returns an array containing the selected item. * This method is implemented for compatibility with * <code>ItemSelectable</code>. * * @return an array of <code>Objects</code> containing one * element -- the selected item */ public Object[] getSelectedObjects() { Object selectedObject = getSelectedItem(); if ( selectedObject == null ) return new Object[0]; else { Object result[] = new Object[1]; result[0] = selectedObject; return result; } } /** * This method is public as an implementation side effect. * do not call or override. */ public void actionPerformed(ActionEvent e) { Object newItem = getEditor().getItem(); setPopupVisible(false); getModel().setSelectedItem(newItem); String oldCommand = getActionCommand(); setActionCommand("comboBoxEdited"); fireActionEvent(); setActionCommand(oldCommand); } /** * This method is public as an implementation side effect. * do not call or override. */ public void contentsChanged(ListDataEvent e) { Object oldSelection = selectedItemReminder; Object newSelection = dataModel.getSelectedItem(); if (oldSelection == null || !oldSelection.equals(newSelection)) { selectedItemChanged(); if (!selectingItem) { fireActionEvent(); } } } /** * This method is public as an implementation side effect. * do not call or override. */ public void intervalAdded(ListDataEvent e) { if (selectedItemReminder != dataModel.getSelectedItem()) { selectedItemChanged(); } } /** * This method is public as an implementation side effect. * do not call or override. */ public void intervalRemoved(ListDataEvent e) { contentsChanged(e); } /** * Selects the list item that corresponds to the specified keyboard * character and returns true, if there is an item corresponding * to that character. Otherwise, returns false. * * @param keyChar a char, typically this is a keyboard key * typed by the user */ public boolean selectWithKeyChar(char keyChar) { int index; if ( keySelectionManager == null ) keySelectionManager = createDefaultKeySelectionManager(); index = keySelectionManager.selectionForKey(keyChar,getModel()); if ( index != -1 ) { setSelectedIndex(index); return true; } else return false; } /** * Enables the combo box so that items can be selected. When the * combo box is disabled, items cannot be selected and values * cannot be typed into its field (if it is editable). * * @param b a boolean value, where true enables the component and * false disables it * @beaninfo * bound: true * preferred: true * description: Whether the combo box is enabled. */ public void setEnabled(boolean b) { super.setEnabled(b); firePropertyChange( "enabled", !isEnabled(), isEnabled() ); } /** * Initializes the editor with the specified item. * * @param anEditor the <code>ComboBoxEditor</code> that displays * the list item in the * combo box field and allows it to be edited * @param anItem the object to display and edit in the field */ public void configureEditor(ComboBoxEditor anEditor, Object anItem) { anEditor.setItem(anItem); } /** * Handles <code>KeyEvent</code>s, looking for the Tab key. * If the Tab key is found, the popup window is closed. * * @param e the <code>KeyEvent</code> containing the keyboard * key that was pressed */ public void processKeyEvent(KeyEvent e) { if ( e.getKeyCode() == KeyEvent.VK_TAB ) { hidePopup(); } super.processKeyEvent(e); } /** * Sets the object that translates a keyboard character into a list * selection. Typically, the first selection with a matching first * character becomes the selected item. * * @beaninfo * expert: true * description: The objects that changes the selection when a key is pressed. */ public void setKeySelectionManager(KeySelectionManager aManager) { keySelectionManager = aManager; } /** * Returns the list's key-selection manager. * * @return the <code>KeySelectionManager</code> currently in use */ public KeySelectionManager getKeySelectionManager() { return keySelectionManager; } /* Accessing the model */ /** * Returns the number of items in the list. * * @return an integer equal to the number of items in the list */ public int getItemCount() { return dataModel.getSize(); } /** * Returns the list item at the specified index. If <code>index</code> * is out of range (less than zero or greater than or equal to size) * it will return <code>null</code>. * * @param index an integer indicating the list position, where the first * item starts at zero * @return the item at that list position; or * <code>null</code> if out of range */ public E getItemAt(int index) { return dataModel.getElementAt(index); } /** * Returns an instance of the default key-selection manager. * * @return the <code>KeySelectionManager</code> currently used by the list * @see #setKeySelectionManager */ protected KeySelectionManager createDefaultKeySelectionManager() { return new DefaultKeySelectionManager(); } /** * The interface that defines a <code>KeySelectionManager</code>. * To qualify as a <code>KeySelectionManager</code>, * the class needs to implement the method * that identifies the list index given a character and the * combo box data model. */ public interface KeySelectionManager { /** Given <code>aKey</code> and the model, returns the row * that should become selected. Return -1 if no match was * found. * * @param aKey a char value, usually indicating a keyboard key that * was pressed * @param aModel a ComboBoxModel -- the component's data model, containing * the list of selectable items * @return an int equal to the selected row, where 0 is the * first item and -1 is none. */ int selectionForKey(char aKey,ComboBoxModel aModel); } class DefaultKeySelectionManager implements KeySelectionManager, Serializable { public int selectionForKey(char aKey,ComboBoxModel aModel) {