javax.swing

Class DefaultComboBoxModel

Implemented Interfaces:
ComboBoxModel, ListModel, MutableComboBoxModel, Serializable

public class DefaultComboBoxModel
extends AbstractListModel
implements MutableComboBoxModel, Serializable

DefaultComboBoxModel is a data model for JComboBox. This model keeps track of elements contained in the JComboBox as well as the current combo box selection. Whenever selection in the JComboBox changes, the ComboBoxModel will fire ListDataEvents to ComboBox's ListDataListeners.

See Also:
Serialized Form

Field Summary

Fields inherited from class javax.swing.AbstractListModel

listenerList

Constructor Summary

DefaultComboBoxModel()
Constructor DefaultComboBoxModel.
DefaultComboBoxModel(Object[] items)
Constructs new DefaultComboBoxModel object and initializes its item list to values in the given array.
DefaultComboBoxModel(Vector vector)
Consturcts new DefaultComboBoxModel object and initializes its item list to values in the given vector.

Method Summary

void
addElement(Object object)
This method adds element to the combo box list.
Object
getElementAt(int index)
Returns element in the combo box list located at the given index
int
getIndexOf(Object object)
Returns index of the specified object in the combo box list.
Object
getSelectedItem()
Returns currently selected item in the combo box list
int
getSize()
Returns number of items in the combo box list
void
insertElementAt(Object object, int index)
This method inserts given object to the combo box list at the specified index.
void
removeAllElements()
Removes all the items from the JComboBox's item list.
void
removeElement(Object object)
Removes given object from the combo box list.
void
removeElementAt(int index)
This method removes element at the specified index from the combo box list.
void
setSelectedItem(Object object)
Selects given object in the combo box list.

Methods inherited from class javax.swing.AbstractListModel

addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DefaultComboBoxModel

public DefaultComboBoxModel()
Constructor DefaultComboBoxModel. Create empty JComboBox.


DefaultComboBoxModel

public DefaultComboBoxModel(Object[] items)
Constructs new DefaultComboBoxModel object and initializes its item list to values in the given array.

Parameters:
items - array containing items of the combo box.


DefaultComboBoxModel

public DefaultComboBoxModel(Vector vector)
Consturcts new DefaultComboBoxModel object and initializes its item list to values in the given vector.

Parameters:
vector - Vector containing items for this combo box.

Method Details

addElement

public void addElement(Object object)
This method adds element to the combo box list. It fires ListDataEvent indicating that component was added to the combo box to all of the JComboBox's registered ListDataListeners.
Specified by:
addElement in interface MutableComboBoxModel

Parameters:
object - item to add to the combo box list


getElementAt

public Object getElementAt(int index)
Returns element in the combo box list located at the given index
Specified by:
getElementAt in interface ListModel

Parameters:
index - specifying location of the element in the list

Returns:
return element in the combo box list located at the given index


getIndexOf

public int getIndexOf(Object object)
Returns index of the specified object in the combo box list.

Parameters:
object - element to look for in the combo box list .

Returns:
Index specifying position of the specified element in combo box list.


getSelectedItem

public Object getSelectedItem()
Returns currently selected item in the combo box list
Specified by:
getSelectedItem in interface ComboBoxModel

Returns:
currently selected item in the combo box list


getSize

public int getSize()
Returns number of items in the combo box list
Specified by:
getSize in interface ListModel

Returns:
number of items in the combo box list


insertElementAt

public void insertElementAt(Object object,
                            int index)
This method inserts given object to the combo box list at the specified index. It fires ListDataEvent indicating that component was inserted to the combo box list to all of the JComboBox's registered ListDataListeners.
Specified by:
insertElementAt in interface MutableComboBoxModel

Parameters:
object - element to insert
index - index specifing position in the list where given element should be inserted.


removeAllElements

public void removeAllElements()
Removes all the items from the JComboBox's item list. It fires ListDataEvent indicating that all the elements were removed from the combo box list to all of the JComboBox's registered ListDataListeners.


removeElement

public void removeElement(Object object)
Removes given object from the combo box list. It fires ListDataEvent indicating that component was removed from the combo box list to all of the JComboBox's registered ListDataListeners.
Specified by:
removeElement in interface MutableComboBoxModel

Parameters:
object - Element that will be removed from the combo box list


removeElementAt

public void removeElementAt(int index)
This method removes element at the specified index from the combo box list. It fires ListDataEvent indicating that component was removed from the combo box list to all of the JComboBox's registered ListDataListeners.
Specified by:
removeElementAt in interface MutableComboBoxModel

Parameters:
index - index specifying location of the element to remove in the combo box list.


setSelectedItem

public void setSelectedItem(Object object)
Selects given object in the combo box list. This method fires ListDataEvent to all registered ListDataListeners of the JComboBox. The start and end index of the event is set to -1 to indicate combo box's selection has changed, and not its contents.

If the given object is not contained in the combo box list then nothing happens.

Specified by:
setSelectedItem in interface ComboBoxModel

Parameters:
object - item to select in the JComboBox


DefaultComboBoxModel.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.