diff options
| author | David Gilbert <david.gilbert@object-refinery.com> | 2006-09-14 10:35:48 +0000 |
|---|---|---|
| committer | David Gilbert <david.gilbert@object-refinery.com> | 2006-09-14 10:35:48 +0000 |
| commit | c09ef45dc0dbebcbbcd4ff6c4caf5db1f2dab4f5 (patch) | |
| tree | ad1792b58d599d3201ee29b904e6e46b83f8a208 /java | |
| parent | 166bef7f6e246e35a5228a15746ce8a1b0f66413 (diff) | |
| download | classpath-c09ef45dc0dbebcbbcd4ff6c4caf5db1f2dab4f5.tar.gz | |
2006-09-14 David Gilbert <david.gilbert@object-refinery.com>
Fixes PR28699
* java/awt/Menu.java
(insert(MenuItem, int)): Fixed loop range,
(insert(String, int)): Updated API docs.
Diffstat (limited to 'java')
| -rw-r--r-- | java/awt/Menu.java | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/java/awt/Menu.java b/java/awt/Menu.java index b9bddcfb6..cef04a38e 100644 --- a/java/awt/Menu.java +++ b/java/awt/Menu.java @@ -216,13 +216,15 @@ public class Menu extends MenuItem implements MenuContainer, Serializable } /** - * Inserts the specified menu item into this menu at the specified index. + * Inserts the specified menu item into this menu at the specified index. If + * the index is greater than or equal to the number of items already in the + * menu, the new item is added as the last item in the menu. * - * @param item The menu item to add. - * @param index The index of the menu item. + * @param item The menu item to add (<code>null</code> not permitted). + * @param index The index of the menu item (>= 0). * - * @exception IllegalArgumentException If the index is less than zero. - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. + * @throws IllegalArgumentException if the index is less than zero. + * @throws NullPointerException if <code>item</code> is <code>null</code>. */ public void insert(MenuItem item, int index) { @@ -252,20 +254,23 @@ public class Menu extends MenuItem implements MenuContainer, Serializable item.addNotify(); peer.addItem(item); - for (int i = index; i < count; i++) + // bear in mind that count is the number of items *before* the new + // item was added + for (int i = index + 1; i <= count; i++) peer.addItem((MenuItem) items.elementAt(i)); } } /** - * Inserts an item with the specified label into this menu at the specified index. + * Inserts an item with the specified label into this menu at the specified + * index. If the index is greater than or equal to the number of items + * already in the menu, the new item is added as the last item in the menu. * * @param label The label of the item to add. - * @param index The index of the menu item. + * @param index The index of the menu item (>= 0). * - * @exception IllegalArgumentException If the index is less than zero. - * @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid. + * @throws IllegalArgumentException If the index is less than zero. */ public void insert(String label, int index) { |
