Hi Pavel,
here is a patch to "generify" JComboBox along with: ComboBoxEditor,
ComboBoxModel,
DefaultComboBoxModel and MutableComboBoxModel.
I fixed the BasicComboBoxEditor as I proposed in my last post.
MutableComboBoxModel.removeElement is not generified currently and thus still
takes an Object as argument. This is consistent with the Collection Framework
(eg. java.util.List.remove). Please tell me if you prefer this method to take a
generic parameter as well.
I also created a new issue in the OpenJDK Bugzilla system:
https://bugs.openjdk.java.net/show_bug.cgi?id=100153
Regards,
Florian
diff -r 940fed1764b4 src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java
--- a/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java Sun Oct 10 14:28:59 2010 +0100
@@ -480,8 +480,8 @@
/**
* Subclassed to highlight selected item in an editable combo box.
*/
- public static class WindowsComboBoxEditor
- extends BasicComboBoxEditor.UIResource {
+ public static class WindowsComboBoxEditor<E>
+ extends BasicComboBoxEditor.UIResource<E> {
/**
* {...@inheritdoc}
@@ -497,7 +497,7 @@
return editor;
}
- public void setItem(Object item) {
+ public void setItem(E item) {
super.setItem(item);
if (editor.hasFocus()) {
editor.selectAll();
diff -r 940fed1764b4 src/share/classes/javax/swing/ComboBoxEditor.java
--- a/src/share/classes/javax/swing/ComboBoxEditor.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/ComboBoxEditor.java Sun Oct 10 14:28:59 2010 +0100
@@ -30,9 +30,11 @@
/**
* The editor component used for JComboBox components.
*
+ * @param <E> the type of the item to edit
+ *
* @author Arnaud Weber
*/
-public interface ComboBoxEditor {
+public interface ComboBoxEditor<E> {
/** Return the component that should be added to the tree hierarchy for
* this editor
@@ -40,10 +42,10 @@
public Component getEditorComponent();
/** Set the item that should be edited. Cancel any editing if necessary **/
- public void setItem(Object anObject);
+ public void setItem(E item);
/** Return the edited item **/
- public Object getItem();
+ public E getItem();
/** Ask the editor to start editing and to select everything **/
public void selectAll();
diff -r 940fed1764b4 src/share/classes/javax/swing/ComboBoxModel.java
--- a/src/share/classes/javax/swing/ComboBoxModel.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/ComboBoxModel.java Sun Oct 10 14:28:59 2010 +0100
@@ -33,9 +33,11 @@
* <code>ListModel</code>. This disjoint behavior allows for the temporary
* storage and retrieval of a selected item in the model.
*
+ * @param <E> the type of the elements of this model
+ *
* @author Arnaud Weber
*/
-public interface ComboBoxModel extends ListModel {
+public interface ComboBoxModel<E> extends ListModel<E> {
/**
* Set the selected item. The implementation of this method should notify
@@ -45,11 +47,11 @@
* @param anItem the list object to select or <code>null</code>
* to clear the selection
*/
- void setSelectedItem(Object anItem);
+ void setSelectedItem(E anItem);
/**
* Returns the selected item
* @return The selected item or <code>null</code> if there is no selection
*/
- Object getSelectedItem();
+ E getSelectedItem();
}
diff -r 940fed1764b4 src/share/classes/javax/swing/DefaultComboBoxModel.java
--- a/src/share/classes/javax/swing/DefaultComboBoxModel.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/DefaultComboBoxModel.java Sun Oct 10 14:28:59 2010 +0100
@@ -44,19 +44,21 @@
/**
* The default model for combo boxes.
*
+ * @param <E> the type of the elements of this model
+ *
* @author Arnaud Weber
* @author Tom Santos
*/
-public class DefaultComboBoxModel extends AbstractListModel implements MutableComboBoxModel, Serializable {
- Vector objects;
- Object selectedObject;
+public class DefaultComboBoxModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable {
+ Vector<E> objects;
+ E selectedObject;
/**
* Constructs an empty DefaultComboBoxModel object.
*/
public DefaultComboBoxModel() {
- objects = new Vector();
+ objects = new Vector<E>();
}
/**
@@ -65,8 +67,8 @@
*
* @param items an array of Object objects
*/
- public DefaultComboBoxModel(final Object items[]) {
- objects = new Vector();
+ public DefaultComboBoxModel(final E items[]) {
+ objects = new Vector<E>();
objects.ensureCapacity( items.length );
int i,c;
@@ -84,7 +86,7 @@
*
* @param v a Vector object ...
*/
- public DefaultComboBoxModel(Vector<?> v) {
+ public DefaultComboBoxModel(Vector<E> v) {
objects = v;
if ( getSize() > 0 ) {
@@ -96,18 +98,18 @@
/**
* Set the value of the selected item. The selected item may be null.
* <p>
- * @param anObject The combo box value or null for no selection.
+ * @param item The combo box value or null for no selection.
*/
- public void setSelectedItem(Object anObject) {
- if ((selectedObject != null && !selectedObject.equals( anObject )) ||
- selectedObject == null && anObject != null) {
- selectedObject = anObject;
+ public void setSelectedItem(E item) {
+ if ((selectedObject != null && !selectedObject.equals( item )) ||
+ selectedObject == null && item != null) {
+ selectedObject = item;
fireContentsChanged(this, -1, -1);
}
}
// implements javax.swing.ComboBoxModel
- public Object getSelectedItem() {
+ public E getSelectedItem() {
return selectedObject;
}
@@ -117,7 +119,7 @@
}
// implements javax.swing.ListModel
- public Object getElementAt(int index) {
+ public E getElementAt(int index) {
if ( index >= 0 && index < objects.size() )
return objects.elementAt(index);
else
@@ -136,7 +138,7 @@
}
// implements javax.swing.MutableComboBoxModel
- public void addElement(Object anObject) {
+ public void addElement(E anObject) {
objects.addElement(anObject);
fireIntervalAdded(this,objects.size()-1, objects.size()-1);
if ( objects.size() == 1 && selectedObject == null && anObject != null ) {
@@ -145,7 +147,7 @@
}
// implements javax.swing.MutableComboBoxModel
- public void insertElementAt(Object anObject,int index) {
+ public void insertElementAt(E anObject,int index) {
objects.insertElementAt(anObject,index);
fireIntervalAdded(this, index, index);
}
diff -r 940fed1764b4 src/share/classes/javax/swing/JComboBox.java
--- a/src/share/classes/javax/swing/JComboBox.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/JComboBox.java Sun Oct 10 14:28:59 2010 +0100
@@ -69,6 +69,8 @@
* @see ComboBoxModel
* @see DefaultComboBoxModel
*
+ * @param <E> the type of the elements of this combo box
+ *
* @beaninfo
* attribute: isContainer false
* description: A combination of a text field and a drop-down list.
@@ -76,7 +78,7 @@
* @author Arnaud Weber
* @author Mark Davidson
*/
-public class JComboBox extends JComponent
+public class JComboBox<E> extends JComponent
implements ItemSelectable,ListDataListener,ActionListener, Accessible {
/**
* @see #getUIClassID
@@ -91,7 +93,7 @@
* @see #getModel
* @see #setModel
*/
- protected ComboBoxModel dataModel;
+ protected ComboBoxModel<E> dataModel;
/**
* This protected field is implementation specific. Do not access directly
* or override. Use the accessor methods instead.
@@ -99,7 +101,7 @@
* @see #getRenderer
* @see #setRenderer
*/
- protected ListCellRenderer renderer;
+ protected ListCellRenderer<? super E> renderer;
/**
* This protected field is implementation specific. Do not access directly
* or override. Use the accessor methods instead.
@@ -107,7 +109,7 @@
* @see #getEditor
* @see #setEditor
*/
- protected ComboBoxEditor editor;
+ protected ComboBoxEditor<E> editor;
/**
* This protected field is implementation specific. Do not access directly
* or override. Use the accessor methods instead.
@@ -154,9 +156,9 @@
* This protected field is implementation specific. Do not access directly
* or override.
*/
- protected Object selectedItemReminder = null;
+ protected E selectedItemReminder = null;
- private Object prototypeDisplayValue;
+ private E prototypeDisplayValue;
// Flag to ensure that infinite loops do not occur with ActionEvents.
private boolean firingActionEvent = false;
@@ -175,7 +177,7 @@
* displayed list of items
* @see DefaultComboBoxModel
*/
- public JComboBox(ComboBoxModel aModel) {
+ public JComboBox(ComboBoxModel<E> aModel) {
super();
setModel(aModel);
init();
@@ -189,9 +191,9 @@
* @param items an array of objects to insert into the combo box
* @see DefaultComboBoxModel
*/
- public JComboBox(final Object items[]) {
+ public JComboBox(final E items[]) {
super();
- setModel(new DefaultComboBoxModel(items));
+ setModel(new DefaultComboBoxModel<E>(items));
init();
}
@@ -203,9 +205,9 @@
* @param items an array of vectors to insert into the combo box
* @see DefaultComboBoxModel
*/
- public JComboBox(Vector<?> items) {
+ public JComboBox(Vector<E> items) {
super();
- setModel(new DefaultComboBoxModel(items));
+ setModel(new DefaultComboBoxModel<E>(items));
init();
}
@@ -219,7 +221,7 @@
*/
public JComboBox() {
super();
- setModel(new DefaultComboBoxModel());
+ setModel(new DefaultComboBoxModel<E>());
init();
}
@@ -263,7 +265,7 @@
public void updateUI() {
setUI((ComboBoxUI)UIManager.getUI(this));
- ListCellRenderer renderer = getRenderer();
+ ListCellRenderer<? super E> renderer = getRenderer();
if (renderer instanceof Component) {
SwingUtilities.updateComponentTreeUI((Component)renderer);
}
@@ -302,8 +304,8 @@
* bound: true
* description: Model that the combo box uses to get data to display.
*/
- public void setModel(ComboBoxModel aModel) {
- ComboBoxModel oldModel = dataModel;
+ public void setModel(ComboBoxModel<E> aModel) {
+ ComboBoxModel<E> oldModel = dataModel;
if (oldModel != null) {
oldModel.removeListDataListener(this);
}
@@ -322,7 +324,7 @@
* @return the <code>ComboBoxModel</code> that provides the displayed
* list of items
*/
- public ComboBoxModel getModel() {
+ public ComboBoxModel<E> getModel() {
return dataModel;
}
@@ -461,8 +463,8 @@
* expert: true
* description: The renderer that paints the item selected in the list.
*/
- public void setRenderer(ListCellRenderer aRenderer) {
- ListCellRenderer oldRenderer = renderer;
+ public void setRenderer(ListCellRenderer<? super E> aRenderer) {
+ ListCellRenderer<? super E> oldRenderer = renderer;
renderer = aRenderer;
firePropertyChange( "renderer", oldRenderer, renderer );
invalidate();
@@ -475,7 +477,7 @@
* @return the <code>ListCellRenderer</code> that displays
* the selected item.
*/
- public ListCellRenderer getRenderer() {
+ public ListCellRenderer<? super E> getRenderer() {
return renderer;
}
@@ -493,8 +495,8 @@
* expert: true
* description: The editor that combo box uses to edit the current value
*/
- public void setEditor(ComboBoxEditor anEditor) {
- ComboBoxEditor oldEditor = editor;
+ public void setEditor(ComboBoxEditor<E> anEditor) {
+ ComboBoxEditor<E> oldEditor = editor;
if ( editor != null ) {
editor.removeActionListener(this);
@@ -512,7 +514,7 @@
*
* @return the <code>ComboBoxEditor</code> that displays the selected item
*/
- public ComboBoxEditor getEditor() {
+ public ComboBoxEditor<E> getEditor() {
return editor;
}
@@ -523,45 +525,45 @@
/**
* 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.
+ * If <code>item</code> is in the list, the display area shows
+ * <code>item</code> selected.
* <p>
- * If <code>anObject</code> is <i>not</i> in the list and the combo box is
+ * If <code>item</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>.
+ * combo boxes, the selection will change to <code>item</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
+ * If <code>item</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
+ * @param item the list item to select; use <code>null</code> to
clear the selection
* @beaninfo
* preferred: true
* description: Sets the selected item in the JComboBox.
*/
- public void setSelectedItem(Object anObject) {
- Object oldSelection = selectedItemReminder;
- Object objectToSelect = anObject;
- if (oldSelection == null || !oldSelection.equals(anObject)) {
+ public void setSelectedItem(E item) {
+ E oldSelection = selectedItemReminder;
+ E itemToSelect = item;
+ if (oldSelection == null || !oldSelection.equals(item)) {
- if (anObject != null && !isEditable()) {
+ if (item != null && !isEditable()) {
// For non editable combo boxes, an invalid selection
// will be rejected.
boolean found = false;
for (int i = 0; i < dataModel.getSize(); i++) {
- Object element = dataModel.getElementAt(i);
- if (anObject.equals(element)) {
+ E element = dataModel.getElementAt(i);
+ if (item.equals(element)) {
found = true;
- objectToSelect = element;
+ itemToSelect = element;
break;
}
}
@@ -573,7 +575,7 @@
// Must toggle the state of this flag since this method
// call may result in ListDataEvents being fired.
selectingItem = true;
- dataModel.setSelectedItem(objectToSelect);
+ dataModel.setSelectedItem(itemToSelect);
selectingItem = false;
if (selectedItemReminder != dataModel.getSelectedItem()) {
@@ -596,7 +598,7 @@
* @return the current selected Object
* @see #setSelectedItem
*/
- public Object getSelectedItem() {
+ public E getSelectedItem() {
return dataModel.getSelectedItem();
}
@@ -638,9 +640,9 @@
*/
@Transient
public int getSelectedIndex() {
- Object sObject = dataModel.getSelectedItem();
+ E sObject = dataModel.getSelectedItem();
int i,c;
- Object obj;
+ E obj;
for ( i=0,c=dataModel.getSize();i<c;i++ ) {
obj = dataModel.getElementAt(i);
@@ -658,7 +660,7 @@
* @see #setPrototypeDisplayValue
* @since 1.4
*/
- public Object getPrototypeDisplayValue() {
+ public E getPrototypeDisplayValue() {
return prototypeDisplayValue;
}
@@ -683,7 +685,7 @@
* attribute: visualUpdate true
* description: The display prototype value, used to compute display width and height.
*/
- public void setPrototypeDisplayValue(Object prototypeDisplayValue) {
+ public void setPrototypeDisplayValue(E prototypeDisplayValue) {
Object oldValue = this.prototypeDisplayValue;
this.prototypeDisplayValue = prototypeDisplayValue;
firePropertyChange("prototypeDisplayValue", oldValue, prototypeDisplayValue);
@@ -708,12 +710,12 @@
* }
* </pre>
*
- * @param anObject the Object to add to the list
+ * @param item the item to add to the list
* @see MutableComboBoxModel
*/
- public void addItem(Object anObject) {
+ public void addItem(E item) {
checkMutableComboBoxModel();
- ((MutableComboBoxModel)dataModel).addElement(anObject);
+ ((MutableComboBoxModel<E>)dataModel).addElement(item);
}
/**
@@ -721,14 +723,14 @@
* This method works only if the <code>JComboBox</code> uses a
* mutable data model.
*
- * @param anObject the <code>Object</code> to add to the list
+ * @param item the item to add to the list
* @param index an integer specifying the position at which
* to add the item
* @see MutableComboBoxModel
*/
- public void insertItemAt(Object anObject, int index) {
+ public void insertItemAt(E item, int index) {
checkMutableComboBoxModel();
- ((MutableComboBoxModel)dataModel).insertElementAt(anObject,index);
+ ((MutableComboBoxModel<E>)dataModel).insertElementAt(item,index);
}
/**
@@ -736,12 +738,12 @@
* This method works only if the <code>JComboBox</code> uses a
* mutable data model.
*
- * @param anObject the object to remove from the item list
+ * @param item the item to remove from the item list
* @see MutableComboBoxModel
*/
- public void removeItem(Object anObject) {
+ public void removeItem(E item) {
checkMutableComboBoxModel();
- ((MutableComboBoxModel)dataModel).removeElement(anObject);
+ ((MutableComboBoxModel<E>)dataModel).removeElement(item);
}
/**
@@ -756,7 +758,7 @@
*/
public void removeItemAt(int anIndex) {
checkMutableComboBoxModel();
- ((MutableComboBoxModel)dataModel).removeElementAt( anIndex );
+ ((MutableComboBoxModel<E>)dataModel).removeElementAt( anIndex );
}
/**
@@ -764,15 +766,15 @@
*/
public void removeAllItems() {
checkMutableComboBoxModel();
- MutableComboBoxModel model = (MutableComboBoxModel)dataModel;
+ MutableComboBoxModel<E> model = (MutableComboBoxModel<E>)dataModel;
int size = model.getSize();
if ( model instanceof DefaultComboBoxModel ) {
- ((DefaultComboBoxModel)model).removeAllElements();
+ ((DefaultComboBoxModel<E>)model).removeAllElements();
}
else {
for ( int i = 0; i < size; ++i ) {
- Object element = model.getElementAt( 0 );
+ E element = model.getElementAt( 0 );
model.removeElement( element );
}
}
@@ -1188,11 +1190,11 @@
private static class ComboBoxActionPropertyChangeListener
- extends ActionPropertyChangeListener<JComboBox> {
- ComboBoxActionPropertyChangeListener(JComboBox b, Action a) {
+ extends ActionPropertyChangeListener<JComboBox<?>> {
+ ComboBoxActionPropertyChangeListener(JComboBox<?> b, Action a) {
super(b, a);
}
- protected void actionPropertyChanged(JComboBox cb,
+ protected void actionPropertyChanged(JComboBox<?> cb,
Action action,
PropertyChangeEvent e) {
if (AbstractAction.shouldReconfigure(e)) {
@@ -1307,7 +1309,7 @@
* do not call or override.
*/
public void actionPerformed(ActionEvent e) {
- Object newItem = getEditor().getItem();
+ E newItem = getEditor().getItem();
setPopupVisible(false);
getModel().setSelectedItem(newItem);
String oldCommand = getActionCommand();
@@ -1321,8 +1323,8 @@
* do not call or override.
*/
public void contentsChanged(ListDataEvent e) {
- Object oldSelection = selectedItemReminder;
- Object newSelection = dataModel.getSelectedItem();
+ E oldSelection = selectedItemReminder;
+ E newSelection = dataModel.getSelectedItem();
if (oldSelection == null || !oldSelection.equals(newSelection)) {
selectedItemChanged();
if (!selectingItem) {
@@ -1397,7 +1399,7 @@
* 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) {
+ public void configureEditor(ComboBoxEditor<E> anEditor, E anItem) {
anEditor.setItem(anItem);
}
@@ -1454,10 +1456,10 @@
*
* @param index an integer indicating the list position, where the first
* item starts at zero
- * @return the <code>Object</code> at that list position; or
+ * @return the item at that list position; or
* <code>null</code> if out of range
*/
- public Object getItemAt(int index) {
+ public E getItemAt(int index) {
return dataModel.getElementAt(index);
}
@@ -1491,11 +1493,11 @@
* @return an int equal to the selected row, where 0 is the
* first item and -1 is none.
*/
- int selectionForKey(char aKey,ComboBoxModel aModel);
+ int selectionForKey(char aKey,ComboBoxModel<?> aModel);
}
class DefaultKeySelectionManager implements KeySelectionManager, Serializable {
- public int selectionForKey(char aKey,ComboBoxModel aModel) {
+ public int selectionForKey(char aKey,ComboBoxModel<?> aModel) {
int i,c;
int currentSelection = -1;
Object selectedItem = aModel.getSelectedItem();
@@ -1616,7 +1618,7 @@
implements AccessibleAction, AccessibleSelection {
- private JList popupList; // combo box popup list
+ private JList<?> popupList; // combo box popup list
private Accessible previousSelectedAccessible = null;
/**
@@ -1660,7 +1662,7 @@
* Sets the combo box editor's accessible name and descripton
*/
private void setEditorNameAndDescription() {
- ComboBoxEditor editor = JComboBox.this.getEditor();
+ ComboBoxEditor<E> editor = JComboBox.this.getEditor();
if (editor != null) {
Component comp = editor.getEditorComponent();
if (comp instanceof Accessible) {
diff -r 940fed1764b4 src/share/classes/javax/swing/MutableComboBoxModel.java
--- a/src/share/classes/javax/swing/MutableComboBoxModel.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/MutableComboBoxModel.java Sun Oct 10 14:28:59 2010 +0100
@@ -30,16 +30,16 @@
* @author Tom Santos
*/
-public interface MutableComboBoxModel extends ComboBoxModel {
+public interface MutableComboBoxModel<E> extends ComboBoxModel<E> {
/**
* Adds an item at the end of the model. The implementation of this method
* should notify all registered <code>ListDataListener</code>s that the
* item has been added.
*
- * @param obj the <code>Object</code> to be added
+ * @param item the item to be added
*/
- public void addElement( Object obj );
+ public void addElement( E item );
/**
* Removes an item from the model. The implementation of this method should
@@ -55,17 +55,17 @@
* should notify all registered <code>ListDataListener</code>s that the
* item has been added.
*
- * @param obj the <code>Object</code> to be added
+ * @param item the item to be added
* @param index location to add the object
*/
- public void insertElementAt( Object obj, int index );
+ public void insertElementAt( E item, int index );
/**
* Removes an item at a specific index. The implementation of this method
* should notify all registered <code>ListDataListener</code>s that the
* item has been removed.
*
- * @param index location of object to be removed
+ * @param index location of the item to be removed
*/
public void removeElementAt( int index );
}
diff -r 940fed1764b4 src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java
--- a/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java Sun Oct 10 14:28:59 2010 +0100
@@ -38,9 +38,9 @@
* @author Arnaud Weber
* @author Mark Davidson
*/
-public class BasicComboBoxEditor implements ComboBoxEditor,FocusListener {
+public class BasicComboBoxEditor<E> implements ComboBoxEditor<E>,FocusListener {
protected JTextField editor;
- private Object oldValue;
+ private E oldValue;
public BasicComboBoxEditor() {
editor = createEditorComponent();
@@ -66,14 +66,14 @@
/**
* Sets the item that should be edited.
*
- * @param anObject the displayed value of the editor
+ * @param item the displayed value of the editor
*/
- public void setItem(Object anObject) {
+ public void setItem(E item) {
String text;
- if ( anObject != null ) {
- text = anObject.toString();
- oldValue = anObject;
+ if ( item != null ) {
+ text = item.toString();
+ oldValue = item;
} else {
text = "";
}
@@ -83,7 +83,8 @@
}
}
- public Object getItem() {
+ @SuppressWarnings("unchecked")
+ public E getItem() {
Object newValue = editor.getText();
if (oldValue != null && !(oldValue instanceof String)) {
@@ -97,12 +98,17 @@
try {
Method method = cls.getMethod("valueOf", new Class[]{String.class});
newValue = method.invoke(oldValue, new Object[] { editor.getText()});
+ return (E) newValue;
} catch (Exception ex) {
- // Fail silently and return the newValue (a String object)
+ // Fail silently and return null
}
}
}
- return newValue;
+ if (oldValue instanceof String) {
+ return (E) newValue;
+ } else {
+ return null;
+ }
}
public void selectAll() {
@@ -161,7 +167,7 @@
* has been added to the <code>java.beans</code> package.
* Please see {...@link java.beans.XMLEncoder}.
*/
- public static class UIResource extends BasicComboBoxEditor
+ public static class UIResource<E> extends BasicComboBoxEditor<E>
implements javax.swing.plaf.UIResource {
}
}
diff -r 940fed1764b4 src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java
--- a/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java Fri Oct 08 09:50:56 2010 +0900
+++ b/src/share/classes/javax/swing/plaf/metal/MetalComboBoxEditor.java Sun Oct 10 14:28:59 2010 +0100
@@ -47,7 +47,7 @@
*
* @author Steve Wilson
*/
-public class MetalComboBoxEditor extends BasicComboBoxEditor {
+public class MetalComboBoxEditor<E> extends BasicComboBoxEditor<E> {
public MetalComboBoxEditor() {
super();
@@ -133,7 +133,7 @@
* has been added to the <code>java.beans</code> package.
* Please see {...@link java.beans.XMLEncoder}.
*/
- public static class UIResource extends MetalComboBoxEditor
+ public static class UIResource<E> extends MetalComboBoxEditor<E>
implements javax.swing.plaf.UIResource {
}
}