< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -22,12 +22,12 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 package javax.swing;
 
-import java.util.*;
-
+import java.util.Collection;
+import java.util.Vector;
 import java.io.Serializable;
 
 /**
  * The default model for combo boxes.
  *

@@ -175,6 +175,49 @@
             fireIntervalRemoved(this, firstIndex, lastIndex);
         } else {
             selectedObject = null;
         }
     }
+
+    /**
+     * Adds all of the elements present in the collection.
+     * <p>
+     * 
+     * @param c the collection which contains the elements to add.
+     */
+    public void addElements(Collection<E> c) {
+        if (c.isEmpty()) {
+            return;
+        }
+
+        int startIndex = getSize();
+
+        objects.addAll(c);
+        fireIntervalAdded(this, startIndex, getSize());
+    }
+
+    /**
+     * Add all of the elements present in the collection, starting
+     * from the index specified.
+     * <p>
+     * Throws an <code>IllegalArgumentException</code>
+     * if the index was invalid.
+     * 
+     * @param index the index from which to start adding elements from.
+     * @param c the collection which contains the elements to add
+     * @exception IllegalArgumentException if <code>c</code> doesn't fall
+     * in the range of the list.
+     */
+    public void addElementsAt(int index, Collection<E> c) {
+        if (index < 0 || index > getSize()) {
+            throw new IllegalArgumentException(
+                "index must be >=0 and <= number of elements in the combobox.");
+        }
+
+        if (c.isEmpty()) {
+            return;
+        }
+
+        objects.addAll(index, c);
+        fireIntervalAdded(this, index, index + c.size());
+    }
 }
< prev index next >