[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: DefaultComboBoxModel.addElement()
From: |
David Gilbert |
Subject: |
[cp-patches] FYI: DefaultComboBoxModel.addElement() |
Date: |
Sat, 24 Sep 2005 21:45:53 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050728) |
I committed this patch:
2005-09-24 David Gilbert <address@hidden>
* javax/swing/DefaultComboBoxModel.java
(addElement): always fire event for interval added, and call
setSelectedItem() if this is the first item.
The new implementation for addElement() that I committed yesterday was bugging me a
little - although it passed the Mauve tests I wrote, it didn't feel right that it
was treating the first item added as such a special case. Then today I had the
thought that perhaps the method should be generating two ListDataEvents for this
special case...one for the add, and one for making the new item the selected item.
I modified the Mauve test to confirm this, then changed the addElement()
implementation as above. Now it makes sense (to me, anyway)...
Regards,
Dave
Index: javax/swing/DefaultComboBoxModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultComboBoxModel.java,v
retrieving revision 1.12
diff -u -r1.12 DefaultComboBoxModel.java
--- javax/swing/DefaultComboBoxModel.java 24 Sep 2005 06:53:50 -0000
1.12
+++ javax/swing/DefaultComboBoxModel.java 24 Sep 2005 20:17:10 -0000
@@ -113,24 +113,17 @@
/**
* Adds an element to the model's item list and sends a address@hidden
ListDataEvent}
- * to all registered listeners. If the item list is empty, the new element
- * also becomes the model's selected item.
+ * to all registered listeners. If the new element is the first item added
+ * to the list, it is set as the selected item.
*
* @param object item to add to the model's item list.
*/
public void addElement(Object object)
{
- if (list.size() == 0)
- {
- list.add(object);
- selectedItem = object;
- fireContentsChanged(this, -1, -1);
- }
- else
- {
- list.add(object);
- fireIntervalAdded(this, list.size() - 1, list.size() - 1);
- }
+ list.add(object);
+ fireIntervalAdded(this, list.size() - 1, list.size() - 1);
+ if (list.size() == 1)
+ setSelectedItem(object);
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: DefaultComboBoxModel.addElement(),
David Gilbert <=