< prev index next >

src/java.desktop/share/classes/javax/swing/JComboBox.java

Print this page

        

*** 56,66 **** * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * <p> * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a> * in <a href="http://docs.oracle.com/javase/tutorial/"><em>The Java Tutorial</em></a> --- 56,66 ---- * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. * * <p> * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html">How to Use Combo Boxes</a> * in <a href="http://docs.oracle.com/javase/tutorial/"><em>The Java Tutorial</em></a>
*** 167,194 **** // Flag to ensure the we don't get multiple ActionEvents on item selection. private boolean selectingItem = false; /** ! * Creates a <code>JComboBox</code> that takes its items from an ! * existing <code>ComboBoxModel</code>. Since the ! * <code>ComboBoxModel</code> is provided, a combo box created using * this constructor does not create a default combo box model and * may impact how the insert, remove and add methods behave. * ! * @param aModel the <code>ComboBoxModel</code> that provides the * displayed list of items * @see DefaultComboBoxModel */ public JComboBox(ComboBoxModel<E> aModel) { super(); setModel(aModel); init(); } /** ! * Creates a <code>JComboBox</code> that contains the elements * in the specified array. By default the first item in the array * (and therefore the data model) becomes selected. * * @param items an array of objects to insert into the combo box * @see DefaultComboBoxModel --- 167,194 ---- // Flag to ensure the we don't get multiple ActionEvents on item selection. private boolean selectingItem = false; /** ! * Creates a {@code JComboBox} that takes its items from an ! * existing {@code ComboBoxModel}. Since the ! * {@code ComboBoxModel} is provided, a combo box created using * this constructor does not create a default combo box model and * may impact how the insert, remove and add methods behave. * ! * @param aModel the {@code ComboBoxModel} that provides the * displayed list of items * @see DefaultComboBoxModel */ public JComboBox(ComboBoxModel<E> aModel) { super(); setModel(aModel); init(); } /** ! * Creates a {@code JComboBox} that contains the elements * in the specified array. By default the first item in the array * (and therefore the data model) becomes selected. * * @param items an array of objects to insert into the combo box * @see DefaultComboBoxModel
*** 198,208 **** setModel(new DefaultComboBoxModel<E>(items)); init(); } /** ! * Creates a <code>JComboBox</code> that contains the elements * in the specified Vector. By default the first item in the vector * (and therefore the data model) becomes selected. * * @param items an array of vectors to insert into the combo box * @see DefaultComboBoxModel --- 198,208 ---- setModel(new DefaultComboBoxModel<E>(items)); init(); } /** ! * Creates a {@code JComboBox} that contains the elements * in the specified Vector. By default the first item in the vector * (and therefore the data model) becomes selected. * * @param items an array of vectors to insert into the combo box * @see DefaultComboBoxModel
*** 212,224 **** setModel(new DefaultComboBoxModel<E>(items)); init(); } /** ! * Creates a <code>JComboBox</code> with a default data model. * The default data model is an empty list of objects. ! * Use <code>addItem</code> to add items. By default the first item * in the data model becomes selected. * * @see DefaultComboBoxModel */ public JComboBox() { --- 212,224 ---- setModel(new DefaultComboBoxModel<E>(items)); init(); } /** ! * Creates a {@code JComboBox} with a default data model. * The default data model is an empty list of objects. ! * Use {@code addItem} to add items. By default the first item * in the data model becomes selected. * * @see DefaultComboBoxModel */ public JComboBox() {
*** 251,261 **** } /** * Sets the L&amp;F object that renders this component. * ! * @param ui the <code>ComboBoxUI</code> L&amp;F object * @see UIDefaults#getUI * * @beaninfo * bound: true * hidden: true --- 251,261 ---- } /** * Sets the L&amp;F object that renders this component. * ! * @param ui the {@code ComboBoxUI} L&amp;F object * @see UIDefaults#getUI * * @beaninfo * bound: true * hidden: true
*** 301,314 **** public ComboBoxUI getUI() { return(ComboBoxUI)ui; } /** ! * Sets the data model that the <code>JComboBox</code> uses to obtain * the list of items. * ! * @param aModel the <code>ComboBoxModel</code> that provides the * displayed list of items * * @beaninfo * bound: true * description: Model that the combo box uses to get data to display. --- 301,314 ---- public ComboBoxUI getUI() { return(ComboBoxUI)ui; } /** ! * Sets the data model that the {@code JComboBox} uses to obtain * the list of items. * ! * @param aModel the {@code ComboBoxModel} that provides the * displayed list of items * * @beaninfo * bound: true * description: Model that the combo box uses to get data to display.
*** 326,338 **** firePropertyChange( "model", oldModel, dataModel); } /** ! * Returns the data model currently used by the <code>JComboBox</code>. * ! * @return the <code>ComboBoxModel</code> that provides the displayed * list of items */ public ComboBoxModel<E> getModel() { return dataModel; } --- 326,338 ---- firePropertyChange( "model", oldModel, dataModel); } /** ! * Returns the data model currently used by the {@code JComboBox}. * ! * @return the {@code ComboBoxModel} that provides the displayed * list of items */ public ComboBoxModel<E> getModel() { return dataModel; }
*** 340,400 **** /* * Properties */ /** ! * Sets the <code>lightWeightPopupEnabled</code> property, which * provides a hint as to whether or not a lightweight ! * <code>Component</code> should be used to contain the ! * <code>JComboBox</code>, versus a heavyweight ! * <code>Component</code> such as a <code>Panel</code> ! * or a <code>Window</code>. The decision of lightweight * versus heavyweight is ultimately up to the ! * <code>JComboBox</code>. Lightweight windows are more * efficient than heavyweight windows, but lightweight * and heavyweight components do not mix well in a GUI. * If your application mixes lightweight and heavyweight * components, you should disable lightweight popups. ! * The default value for the <code>lightWeightPopupEnabled</code> ! * property is <code>true</code>, unless otherwise specified * by the look and feel. Some look and feels always use * heavyweight popups, no matter what the value of this property. * <p> * See the article <a href="http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html">Mixing Heavy and Light Components</a> * This method fires a property changed event. * ! * @param aFlag if <code>true</code>, lightweight popups are desired * * @beaninfo * bound: true * expert: true ! * description: Set to <code>false</code> to require heavyweight popups. */ public void setLightWeightPopupEnabled(boolean aFlag) { boolean oldFlag = lightWeightPopupEnabled; lightWeightPopupEnabled = aFlag; firePropertyChange("lightWeightPopupEnabled", oldFlag, lightWeightPopupEnabled); } /** ! * Gets the value of the <code>lightWeightPopupEnabled</code> * property. * ! * @return the value of the <code>lightWeightPopupEnabled</code> * property * @see #setLightWeightPopupEnabled */ public boolean isLightWeightPopupEnabled() { return lightWeightPopupEnabled; } /** ! * Determines whether the <code>JComboBox</code> field is editable. ! * An editable <code>JComboBox</code> allows the user to type into the * field or selected an item from the list to initialize the field, * after which it can be edited. (The editing affects only the field, ! * the list item remains intact.) A non editable <code>JComboBox</code> * displays the selected item in the field, * but the selection cannot be modified. * * @param aFlag a boolean value, where true indicates that the * field is editable --- 340,400 ---- /* * Properties */ /** ! * Sets the {@code lightWeightPopupEnabled} property, which * provides a hint as to whether or not a lightweight ! * {@code Component} should be used to contain the ! * {@code JComboBox}, versus a heavyweight ! * {@code Component} such as a {@code Panel} ! * or a {@code Window}. The decision of lightweight * versus heavyweight is ultimately up to the ! * {@code JComboBox}. Lightweight windows are more * efficient than heavyweight windows, but lightweight * and heavyweight components do not mix well in a GUI. * If your application mixes lightweight and heavyweight * components, you should disable lightweight popups. ! * The default value for the {@code lightWeightPopupEnabled} ! * property is {@code true}, unless otherwise specified * by the look and feel. Some look and feels always use * heavyweight popups, no matter what the value of this property. * <p> * See the article <a href="http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html">Mixing Heavy and Light Components</a> * This method fires a property changed event. * ! * @param aFlag if {@code true}, lightweight popups are desired * * @beaninfo * bound: true * expert: true ! * description: Set to {@code false} to require heavyweight popups. */ public void setLightWeightPopupEnabled(boolean aFlag) { boolean oldFlag = lightWeightPopupEnabled; lightWeightPopupEnabled = aFlag; firePropertyChange("lightWeightPopupEnabled", oldFlag, lightWeightPopupEnabled); } /** ! * Gets the value of the {@code lightWeightPopupEnabled} * property. * ! * @return the value of the {@code lightWeightPopupEnabled} * property * @see #setLightWeightPopupEnabled */ public boolean isLightWeightPopupEnabled() { return lightWeightPopupEnabled; } /** ! * Determines whether the {@code JComboBox} field is editable. ! * An editable {@code JComboBox} allows the user to type into the * field or selected an item from the list to initialize the field, * after which it can be edited. (The editing affects only the field, ! * the list item remains intact.) A non editable {@code JComboBox} * displays the selected item in the field, * but the selection cannot be modified. * * @param aFlag a boolean value, where true indicates that the * field is editable
*** 409,429 **** isEditable = aFlag; firePropertyChange( "editable", oldFlag, isEditable ); } /** ! * Returns true if the <code>JComboBox</code> is editable. * By default, a combo box is not editable. * ! * @return true if the <code>JComboBox</code> is editable, else false */ public boolean isEditable() { return isEditable; } /** ! * Sets the maximum number of rows the <code>JComboBox</code> displays. * If the number of objects in the model is greater than count, * the combo box uses a scrollbar. * * @param count an integer specifying the maximum number of items to * display in the list before using a scrollbar --- 409,429 ---- isEditable = aFlag; firePropertyChange( "editable", oldFlag, isEditable ); } /** ! * Returns true if the {@code JComboBox} is editable. * By default, a combo box is not editable. * ! * @return true if the {@code JComboBox} is editable, else false */ public boolean isEditable() { return isEditable; } /** ! * Sets the maximum number of rows the {@code JComboBox} displays. * If the number of objects in the model is greater than count, * the combo box uses a scrollbar. * * @param count an integer specifying the maximum number of items to * display in the list before using a scrollbar
*** 457,470 **** * <p> * The default renderer displays a string or an icon. * Other renderers can handle graphic images and composite items. * <p> * To display the selected item, ! * <code>aRenderer.getListCellRendererComponent</code> * is called, passing the list object and an index of -1. * ! * @param aRenderer the <code>ListCellRenderer</code> that * displays the selected item * @see #setEditor * @beaninfo * bound: true * expert: true --- 457,470 ---- * <p> * The default renderer displays a string or an icon. * Other renderers can handle graphic images and composite items. * <p> * To display the selected item, ! * {@code aRenderer.getListCellRendererComponent} * is called, passing the list object and an index of -1. * ! * @param aRenderer the {@code ListCellRenderer} that * displays the selected item * @see #setEditor * @beaninfo * bound: true * expert: true
*** 477,502 **** invalidate(); } /** * Returns the renderer used to display the selected item in the ! * <code>JComboBox</code> field. * ! * @return the <code>ListCellRenderer</code> that displays * the selected item. */ public ListCellRenderer<? super E> getRenderer() { return renderer; } /** * Sets the editor used to paint and edit the selected item in the ! * <code>JComboBox</code> field. The editor is used only if the ! * receiving <code>JComboBox</code> is editable. If not editable, * the combo box uses the renderer to paint the selected item. * ! * @param anEditor the <code>ComboBoxEditor</code> that * displays the selected item * @see #setRenderer * @beaninfo * bound: true * expert: true --- 477,502 ---- invalidate(); } /** * Returns the renderer used to display the selected item in the ! * {@code JComboBox} field. * ! * @return the {@code ListCellRenderer} that displays * the selected item. */ public ListCellRenderer<? super E> getRenderer() { return renderer; } /** * Sets the editor used to paint and edit the selected item in the ! * {@code JComboBox} field. The editor is used only if the ! * receiving {@code JComboBox} is editable. If not editable, * the combo box uses the renderer to paint the selected item. * ! * @param anEditor the {@code ComboBoxEditor} that * displays the selected item * @see #setRenderer * @beaninfo * bound: true * expert: true
*** 515,527 **** firePropertyChange( "editor", oldEditor, editor ); } /** * Returns the editor used to paint and edit the selected item in the ! * <code>JComboBox</code> field. * ! * @return the <code>ComboBoxEditor</code> that displays the selected item */ public ComboBoxEditor getEditor() { return editor; } --- 515,527 ---- firePropertyChange( "editor", oldEditor, editor ); } /** * Returns the editor used to paint and edit the selected item in the ! * {@code JComboBox} field. * ! * @return the {@code ComboBoxEditor} that displays the selected item */ public ComboBoxEditor getEditor() { return editor; }
*** 530,559 **** // /** * Sets the selected item in the combo box display area to the object in * the argument. ! * If <code>anObject</code> is in the list, the display area shows ! * <code>anObject</code> selected. * <p> ! * If <code>anObject</code> is <i>not</i> in the list and the combo box is * uneditable, it will not change the current selection. For editable ! * combo boxes, the selection will change to <code>anObject</code>. * <p> * If this constitutes a change in the selected item, ! * <code>ItemListener</code>s added to the combo box will be notified with ! * one or two <code>ItemEvent</code>s. ! * If there is a current selected item, an <code>ItemEvent</code> will be ! * fired and the state change will be <code>ItemEvent.DESELECTED</code>. ! * If <code>anObject</code> is in the list and is not currently selected ! * then an <code>ItemEvent</code> will be fired and the state change will ! * be <code>ItemEvent.SELECTED</code>. * <p> ! * <code>ActionListener</code>s added to the combo box will be notified ! * with an <code>ActionEvent</code> when this method is called. * ! * @param anObject the list object to select; use <code>null</code> to clear the selection * @beaninfo * preferred: true * description: Sets the selected item in the JComboBox. */ --- 530,559 ---- // /** * Sets the selected item in the combo box display area to the object in * the argument. ! * If {@code anObject} is in the list, the display area shows ! * {@code anObject} selected. * <p> ! * If {@code anObject} is <i>not</i> in the list and the combo box is * uneditable, it will not change the current selection. For editable ! * combo boxes, the selection will change to {@code anObject}. * <p> * If this constitutes a change in the selected item, ! * {@code ItemListener}s added to the combo box will be notified with ! * one or two {@code ItemEvent}s. ! * If there is a current selected item, an {@code ItemEvent} will be ! * fired and the state change will be {@code ItemEvent.DESELECTED}. ! * If {@code anObject} is in the list and is not currently selected ! * then an {@code ItemEvent} will be fired and the state change will ! * be {@code ItemEvent.SELECTED}. * <p> ! * {@code ActionListener}s added to the combo box will be notified ! * with an {@code ActionEvent} when this method is called. * ! * @param anObject the list object to select; use {@code null} to clear the selection * @beaninfo * preferred: true * description: Sets the selected item in the JComboBox. */
*** 599,625 **** /** * Returns the current selected item. * <p> * If the combo box is editable, then this value may not have been added ! * to the combo box with <code>addItem</code>, <code>insertItemAt</code> * or the data constructors. * * @return the current selected Object * @see #setSelectedItem */ public Object getSelectedItem() { return dataModel.getSelectedItem(); } /** ! * Selects the item at index <code>anIndex</code>. * * @param anIndex an integer specifying the list item to select, * where 0 specifies the first item in the list and -1 indicates no selection ! * @exception IllegalArgumentException if <code>anIndex</code> &lt; -1 or ! * <code>anIndex</code> is greater than or equal to size * @beaninfo * preferred: true * description: The item at index is selected. */ public void setSelectedIndex(int anIndex) { --- 599,625 ---- /** * Returns the current selected item. * <p> * If the combo box is editable, then this value may not have been added ! * to the combo box with {@code addItem}, {@code insertItemAt} * or the data constructors. * * @return the current selected Object * @see #setSelectedItem */ public Object getSelectedItem() { return dataModel.getSelectedItem(); } /** ! * Selects the item at index {@code anIndex}. * * @param anIndex an integer specifying the list item to select, * where 0 specifies the first item in the list and -1 indicates no selection ! * @exception IllegalArgumentException if {@code anIndex < -1} or ! * {@code anIndex} is greater than or equal to size * @beaninfo * preferred: true * description: The item at index is selected. */ public void setSelectedIndex(int anIndex) {
*** 634,644 **** } } /** * Returns the first item in the list that matches the given item. ! * The result is not always defined if the <code>JComboBox</code> * allows selected items that are not in the list. * Returns -1 if there is no selected item or if the user specified * an item which is not in the list. * @return an integer specifying the currently selected list item, --- 634,644 ---- } } /** * Returns the first item in the list that matches the given item. ! * The result is not always defined if the {@code JComboBox} * allows selected items that are not in the list. * Returns -1 if there is no selected item or if the user specified * an item which is not in the list. * @return an integer specifying the currently selected list item,
*** 663,673 **** /** * Returns the "prototypical display" value - an Object used * for the calculation of the display height and width. * ! * @return the value of the <code>prototypeDisplayValue</code> property * @see #setPrototypeDisplayValue * @since 1.4 */ public E getPrototypeDisplayValue() { return prototypeDisplayValue; --- 663,673 ---- /** * Returns the "prototypical display" value - an Object used * for the calculation of the display height and width. * ! * @return the value of the {@code prototypeDisplayValue} property * @see #setPrototypeDisplayValue * @since 1.4 */ public E getPrototypeDisplayValue() { return prototypeDisplayValue;
*** 700,710 **** firePropertyChange("prototypeDisplayValue", oldValue, prototypeDisplayValue); } /** * Adds an item to the item list. ! * This method works only if the <code>JComboBox</code> uses a * mutable data model. * <p> * <strong>Warning:</strong> * Focus and keyboard navigation problems may arise if you add duplicate * String objects. A workaround is to add new objects instead of String --- 700,710 ---- firePropertyChange("prototypeDisplayValue", oldValue, prototypeDisplayValue); } /** * Adds an item to the item list. ! * This method works only if the {@code JComboBox} uses a * mutable data model. * <p> * <strong>Warning:</strong> * Focus and keyboard navigation problems may arise if you add duplicate * String objects. A workaround is to add new objects instead of String
*** 727,737 **** ((MutableComboBoxModel<E>)dataModel).addElement(item); } /** * Inserts an item into the item list at a given index. ! * This method works only if the <code>JComboBox</code> uses a * mutable data model. * * @param item the item to add to the list * @param index an integer specifying the position at which * to add the item --- 727,737 ---- ((MutableComboBoxModel<E>)dataModel).addElement(item); } /** * Inserts an item into the item list at a given index. ! * This method works only if the {@code JComboBox} uses a * mutable data model. * * @param item the item to add to the list * @param index an integer specifying the position at which * to add the item
*** 742,752 **** ((MutableComboBoxModel<E>)dataModel).insertElementAt(item,index); } /** * Removes an item from the item list. ! * This method works only if the <code>JComboBox</code> uses a * mutable data model. * * @param anObject the object to remove from the item list * @see MutableComboBoxModel */ --- 742,752 ---- ((MutableComboBoxModel<E>)dataModel).insertElementAt(item,index); } /** * Removes an item from the item list. ! * This method works only if the {@code JComboBox} uses a * mutable data model. * * @param anObject the object to remove from the item list * @see MutableComboBoxModel */
*** 754,765 **** checkMutableComboBoxModel(); ((MutableComboBoxModel)dataModel).removeElement(anObject); } /** ! * Removes the item at <code>anIndex</code> ! * This method works only if the <code>JComboBox</code> uses a * mutable data model. * * @param anIndex an int specifying the index of the item to remove, * where 0 * indicates the first item in the list --- 754,765 ---- checkMutableComboBoxModel(); ((MutableComboBoxModel)dataModel).removeElement(anObject); } /** ! * Removes the item at {@code anIndex} ! * This method works only if the {@code JComboBox} uses a * mutable data model. * * @param anIndex an int specifying the index of the item to remove, * where 0 * indicates the first item in the list
*** 792,805 **** editor.setItem(null); } } /** ! * Checks that the <code>dataModel</code> is an instance of ! * <code>MutableComboBoxModel</code>. If not, it throws an exception. ! * @exception RuntimeException if <code>dataModel</code> is not an ! * instance of <code>MutableComboBoxModel</code>. */ void checkMutableComboBoxModel() { if ( !(dataModel instanceof MutableComboBoxModel) ) throw new RuntimeException("Cannot use this method with a non-Mutable data model."); } --- 792,805 ---- editor.setItem(null); } } /** ! * Checks that the {@code dataModel} is an instance of ! * {@code MutableComboBoxModel}. If not, it throws an exception. ! * @exception RuntimeException if {@code dataModel} is not an ! * instance of {@code MutableComboBoxModel}. */ void checkMutableComboBoxModel() { if ( !(dataModel instanceof MutableComboBoxModel) ) throw new RuntimeException("Cannot use this method with a non-Mutable data model."); }
*** 839,959 **** } /** Selection **/ /** ! * Adds an <code>ItemListener</code>. * <p> ! * <code>aListener</code> will receive one or two <code>ItemEvent</code>s when * the selected item changes. * ! * @param aListener the <code>ItemListener</code> that is to be notified * @see #setSelectedItem */ public void addItemListener(ItemListener aListener) { listenerList.add(ItemListener.class,aListener); } ! /** Removes an <code>ItemListener</code>. * ! * @param aListener the <code>ItemListener</code> to remove */ public void removeItemListener(ItemListener aListener) { listenerList.remove(ItemListener.class,aListener); } /** ! * Returns an array of all the <code>ItemListener</code>s added * to this JComboBox with addItemListener(). * ! * @return all of the <code>ItemListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public ItemListener[] getItemListeners() { return listenerList.getListeners(ItemListener.class); } /** ! * Adds an <code>ActionListener</code>. * <p> ! * The <code>ActionListener</code> will receive an <code>ActionEvent</code> * when a selection has been made. If the combo box is editable, then ! * an <code>ActionEvent</code> will be fired when editing has stopped. * ! * @param l the <code>ActionListener</code> that is to be notified * @see #setSelectedItem */ public void addActionListener(ActionListener l) { listenerList.add(ActionListener.class,l); } ! /** Removes an <code>ActionListener</code>. * ! * @param l the <code>ActionListener</code> to remove */ public void removeActionListener(ActionListener l) { if ((l != null) && (getAction() == l)) { setAction(null); } else { listenerList.remove(ActionListener.class, l); } } /** ! * Returns an array of all the <code>ActionListener</code>s added * to this JComboBox with addActionListener(). * ! * @return all of the <code>ActionListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } /** ! * Adds a <code>PopupMenu</code> listener which will listen to notification * messages from the popup portion of the combo box. * <p> * For all standard look and feels shipped with Java, the popup list ! * portion of combo box is implemented as a <code>JPopupMenu</code>. * A custom look and feel may not implement it this way and will * therefore not receive the notification. * ! * @param l the <code>PopupMenuListener</code> to add * @since 1.4 */ public void addPopupMenuListener(PopupMenuListener l) { listenerList.add(PopupMenuListener.class,l); } /** ! * Removes a <code>PopupMenuListener</code>. * ! * @param l the <code>PopupMenuListener</code> to remove * @see #addPopupMenuListener * @since 1.4 */ public void removePopupMenuListener(PopupMenuListener l) { listenerList.remove(PopupMenuListener.class,l); } /** ! * Returns an array of all the <code>PopupMenuListener</code>s added * to this JComboBox with addPopupMenuListener(). * ! * @return all of the <code>PopupMenuListener</code>s added or an empty * array if no listeners have been added * @since 1.4 */ public PopupMenuListener[] getPopupMenuListeners() { return listenerList.getListeners(PopupMenuListener.class); } /** ! * Notifies <code>PopupMenuListener</code>s that the popup portion of the * combo box will become visible. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener --- 839,959 ---- } /** Selection **/ /** ! * Adds an {@code ItemListener}. * <p> ! * {@code aListener} will receive one or two {@code ItemEvent}s when * the selected item changes. * ! * @param aListener the {@code ItemListener} that is to be notified * @see #setSelectedItem */ public void addItemListener(ItemListener aListener) { listenerList.add(ItemListener.class,aListener); } ! /** Removes an {@code ItemListener}. * ! * @param aListener the {@code ItemListener} to remove */ public void removeItemListener(ItemListener aListener) { listenerList.remove(ItemListener.class,aListener); } /** ! * Returns an array of all the {@code ItemListener}s added * to this JComboBox with addItemListener(). * ! * @return all of the {@code ItemListener}s added or an empty * array if no listeners have been added * @since 1.4 */ public ItemListener[] getItemListeners() { return listenerList.getListeners(ItemListener.class); } /** ! * Adds an {@code ActionListener}. * <p> ! * The {@code ActionListener} will receive an {@code ActionEvent} * when a selection has been made. If the combo box is editable, then ! * an {@code ActionEvent} will be fired when editing has stopped. * ! * @param l the {@code ActionListener} that is to be notified * @see #setSelectedItem */ public void addActionListener(ActionListener l) { listenerList.add(ActionListener.class,l); } ! /** Removes an {@code ActionListener}. * ! * @param l the {@code ActionListener} to remove */ public void removeActionListener(ActionListener l) { if ((l != null) && (getAction() == l)) { setAction(null); } else { listenerList.remove(ActionListener.class, l); } } /** ! * Returns an array of all the {@code ActionListener}s added * to this JComboBox with addActionListener(). * ! * @return all of the {@code ActionListener}s added or an empty * array if no listeners have been added * @since 1.4 */ public ActionListener[] getActionListeners() { return listenerList.getListeners(ActionListener.class); } /** ! * Adds a {@code PopupMenu} listener which will listen to notification * messages from the popup portion of the combo box. * <p> * For all standard look and feels shipped with Java, the popup list ! * portion of combo box is implemented as a {@code JPopupMenu}. * A custom look and feel may not implement it this way and will * therefore not receive the notification. * ! * @param l the {@code PopupMenuListener} to add * @since 1.4 */ public void addPopupMenuListener(PopupMenuListener l) { listenerList.add(PopupMenuListener.class,l); } /** ! * Removes a {@code PopupMenuListener}. * ! * @param l the {@code PopupMenuListener} to remove * @see #addPopupMenuListener * @since 1.4 */ public void removePopupMenuListener(PopupMenuListener l) { listenerList.remove(PopupMenuListener.class,l); } /** ! * Returns an array of all the {@code PopupMenuListener}s added * to this JComboBox with addPopupMenuListener(). * ! * @return all of the {@code PopupMenuListener}s added or an empty * array if no listeners have been added * @since 1.4 */ public PopupMenuListener[] getPopupMenuListeners() { return listenerList.getListeners(PopupMenuListener.class); } /** ! * Notifies {@code PopupMenuListener}s that the popup portion of the * combo box will become visible. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener
*** 970,980 **** } } } /** ! * Notifies <code>PopupMenuListener</code>s that the popup portion of the * combo box has become invisible. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener --- 970,980 ---- } } } /** ! * Notifies {@code PopupMenuListener}s that the popup portion of the * combo box has become invisible. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener
*** 991,1001 **** } } } /** ! * Notifies <code>PopupMenuListener</code>s that the popup portion of the * combo box has been canceled. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener --- 991,1001 ---- } } } /** ! * Notifies {@code PopupMenuListener}s that the popup portion of the * combo box has been canceled. * <p> * This method is public but should not be called by anything other than * the UI delegate. * @see #addPopupMenuListener
*** 1039,1075 **** 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 --- 1039,1075 ---- private Action action; private PropertyChangeListener actionPropertyChangeListener; /** ! * Sets the {@code Action} for the {@code ActionEvent} source. ! * The new {@code Action} replaces any previously set ! * {@code Action} but does not affect {@code ActionListeners} ! * independently added with {@code addActionListener}. ! * If the {@code Action} is already a registered ! * {@code ActionListener} for the {@code ActionEvent} source, * it is not re-registered. * <p> ! * Setting the {@code Action} results in immediately changing * all the properties described in <a href="Action.html#buttonActions"> ! * Swing Components Supporting {@code Action}</a>. * Subsequently, the combobox's properties are automatically updated ! * as the {@code Action}'s properties change. * <p> * This method uses three other methods to set ! * and help track the {@code Action}'s property values. ! * It uses the {@code configurePropertiesFromAction} method * to immediately change the combobox's properties. ! * To track changes in the {@code Action}'s property values, ! * this method registers the {@code PropertyChangeListener} ! * returned by {@code createActionPropertyChangeListener}. The * default {@code PropertyChangeListener} invokes the * {@code actionPropertyChanged} method when a property in the * {@code Action} changes. * ! * @param a the {@code Action} for the {@code JComboBox}, ! * or {@code null}. * @since 1.3 * @see Action * @see #getAction * @see #configurePropertiesFromAction * @see #createActionPropertyChangeListener
*** 1112,1143 **** } 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) { --- 1112,1143 ---- } return isListener; } /** ! * Returns the currently set {@code Action} for this ! * {@code ActionEvent} source, or {@code null} if no ! * {@code Action} is set. * ! * @return the {@code Action} for this {@code ActionEvent} ! * source; or {@code null} * @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}. Refer to <a href="Action.html#buttonActions"> ! * Swing Components Supporting {@code Action}</a> for more * details as to which properties this sets. * ! * @param a the {@code Action} from which to get the properties, ! * or {@code null} * @since 1.3 * @see Action * @see #setAction */ protected void configurePropertiesFromAction(Action a) {
*** 1145,1161 **** 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 * @return the {@code PropertyChangeListener} * @since 1.3 * @see Action --- 1145,1161 ---- AbstractAction.setToolTipTextFromAction(this, a); setActionCommandFromAction(a); } /** ! * Creates and returns a {@code PropertyChangeListener} that is * responsible for listening for changes from the specified ! * {@code Action} 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}. * * @param a the combobox's action * @return the {@code PropertyChangeListener} * @since 1.3 * @see Action
*** 1173,1186 **** * 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 */ --- 1173,1186 ---- * 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}</a> for a list of * the properties this method sets. * ! * @param action the {@code Action} associated with this combobox * @param propertyName the name of the property that changed * @since 1.6 * @see Action * @see #configurePropertiesFromAction */
*** 1298,1310 **** } /** * 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 ) --- 1298,1310 ---- } /** * Returns an array containing the selected item. * This method is implemented for compatibility with ! * {@code ItemSelectable}. * ! * @return an array of {@code Objects} containing one * element -- the selected item */ public Object[] getSelectedObjects() { Object selectedObject = getSelectedItem(); if ( selectedObject == null )
*** 1405,1428 **** } /** * 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(); --- 1405,1428 ---- } /** * Initializes the editor with the specified item. * ! * @param anEditor the {@code ComboBoxEditor} 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}s, looking for the Tab key. * If the Tab key is found, the popup window is closed. * ! * @param e the {@code KeyEvent} containing the keyboard * key that was pressed */ public void processKeyEvent(KeyEvent e) { if ( e.getKeyCode() == KeyEvent.VK_TAB ) { hidePopup();
*** 1467,1477 **** } /** * Returns the list's key-selection manager. * ! * @return the <code>KeySelectionManager</code> currently in use */ public KeySelectionManager getKeySelectionManager() { return keySelectionManager; } --- 1467,1477 ---- } /** * Returns the list's key-selection manager. * ! * @return the {@code KeySelectionManager} currently in use */ public KeySelectionManager getKeySelectionManager() { return keySelectionManager; }
*** 1484,1526 **** 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 --- 1484,1526 ---- public int getItemCount() { return dataModel.getSize(); } /** ! * Returns the list item at the specified index. If {@code index} * is out of range (less than zero or greater than or equal to size) ! * it will return {@code null}. * * @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} 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} currently used by the list * @see #setKeySelectionManager */ protected KeySelectionManager createDefaultKeySelectionManager() { return new DefaultKeySelectionManager(); } /** ! * The interface that defines a {@code KeySelectionManager}. ! * To qualify as a {@code KeySelectionManager}, * 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} 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
*** 1573,1584 **** } } /** ! * See <code>readObject</code> and <code>writeObject</code> in ! * <code>JComponent</code> for more * information about serialization in Swing. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); if (getUIClassID().equals(uiClassID)) { --- 1573,1584 ---- } } /** ! * See {@code readObject} and {@code writeObject} in ! * {@code JComponent} for more * information about serialization in Swing. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); if (getUIClassID().equals(uiClassID)) {
*** 1590,1606 **** } } /** ! * Returns a string representation of this <code>JComboBox</code>. * This method is intended to be used only for debugging purposes, * and the content and format of the returned string may vary between * implementations. The returned string may be empty but may not ! * be <code>null</code>. * ! * @return a string representation of this <code>JComboBox</code> */ protected String paramString() { String selectedItemReminderString = (selectedItemReminder != null ? selectedItemReminder.toString() : ""); --- 1590,1606 ---- } } /** ! * Returns a string representation of this {@code JComboBox}. * This method is intended to be used only for debugging purposes, * and the content and format of the returned string may vary between * implementations. The returned string may be empty but may not ! * be {@code null}. * ! * @return a string representation of this {@code JComboBox} */ protected String paramString() { String selectedItemReminderString = (selectedItemReminder != null ? selectedItemReminder.toString() : "");
*** 1636,1655 **** return accessibleContext; } /** * This class implements accessibility support for the ! * <code>JComboBox</code> class. It provides an implementation of the * Java Accessibility API appropriate to Combo Box user-interface elements. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJComboBox extends AccessibleJComponent implements AccessibleAction, AccessibleSelection { --- 1636,1655 ---- return accessibleContext; } /** * This class implements accessibility support for the ! * {@code JComboBox} class. It provides an implementation of the * Java Accessibility API appropriate to Combo Box user-interface elements. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans&trade; ! * has been added to the {@code java.beans} package. * Please see {@link java.beans.XMLEncoder}. */ @SuppressWarnings("serial") // Same-version serialization only protected class AccessibleJComboBox extends AccessibleJComponent implements AccessibleAction, AccessibleSelection {
< prev index next >