FileDocCategorySizeDatePackage
List.javaAPI DocJava SE 6 API62625Tue Jun 10 00:25:16 BST 2008java.awt

List

public class List extends Component implements ItemSelectable, Accessible
The List component presents the user with a scrolling list of text items. The list can be set up so that the user can choose either one item or multiple items.

For example, the code . . .


List lst = new List(4, false);
lst.add("Mercury");
lst.add("Venus");
lst.add("Earth");
lst.add("JavaSoft");
lst.add("Mars");
lst.add("Jupiter");
lst.add("Saturn");
lst.add("Uranus");
lst.add("Neptune");
lst.add("Pluto");
cnt.add(lst);

where cnt is a container, produces the following scrolling list:

Shows a list containing: Venus, Earth, JavaSoft, and Mars. Javasoft is selected.

If the List allows multiple selections, then clicking on an item that is already selected deselects it. In the preceding example, only one item from the scrolling list can be selected at a time, since the second argument when creating the new scrolling list is false. If the List does not allow multiple selections, selecting an item causes any other selected item to be deselected.

Note that the list in the example shown was created with four visible rows. Once the list has been created, the number of visible rows cannot be changed. A default List is created with four rows, so that lst = new List() is equivalent to list = new List(4, false).

Beginning with Java 1.1, the Abstract Window Toolkit sends the List object all mouse, keyboard, and focus events that occur over it. (The old AWT event model is being maintained only for backwards compatibility, and its use is discouraged.)

When an item is selected or deselected by the user, AWT sends an instance of ItemEvent to the list. When the user double-clicks on an item in a scrolling list, AWT sends an instance of ActionEvent to the list following the item event. AWT also generates an action event when the user presses the return key while an item in the list is selected.

If an application wants to perform some action based on an item in this list being selected or activated by the user, it should implement ItemListener or ActionListener as appropriate and register the new listener to receive events from this list.

For multiple-selection scrolling lists, it is considered a better user interface to use an external gesture (such as clicking on a button) to trigger the action.

version
1.110, 07/11/06
author
Sami Shaio
see
java.awt.event.ItemEvent
see
java.awt.event.ItemListener
see
java.awt.event.ActionEvent
see
java.awt.event.ActionListener
since
JDK1.0

Fields Summary
Vector
items
A vector created to contain items which will become part of the List Component.
int
rows
This field will represent the number of visible rows in the List Component. It is specified only once, and that is when the list component is actually created. It will never change.
boolean
multipleMode
multipleMode is a variable that will be set to true if a list component is to be set to multiple selection mode, that is where the user can select more than one item in a list at one time. multipleMode will be set to false if the list component is set to single selection, that is where the user can only select one item on the list at any one time.
int[]
selected
selected is an array that will contain the indices of items that have been selected.
int
visibleIndex
This variable contains the value that will be used when trying to make a particular list item visible.
transient ActionListener
actionListener
transient ItemListener
itemListener
private static final String
base
private static int
nameCounter
private static final long
serialVersionUID
static final int
DEFAULT_VISIBLE_ROWS
The default number of visible rows is 4. A list with zero rows is unusable and unsightly.
private int
listSerializedDataVersion
The List component's Serialized Data Version.
Constructors Summary
public List()
Creates a new scrolling list. By default, there are four visible lines and multiple selections are not allowed. Note that this is a convenience method for List(0, false). Also note that the number of visible lines in the list cannot be changed after it has been created.

exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless


                                                                  
        
	this(0, false);
    
public List(int rows)
Creates a new scrolling list initialized with the specified number of visible lines. By default, multiple selections are not allowed. Note that this is a convenience method for List(rows, false). Also note that the number of visible rows in the list cannot be changed after it has been created.

param
rows the number of items to show.
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless
since
JDK1.1

    	this(rows, false);
    
public List(int rows, boolean multipleMode)
Creates a new scrolling list initialized to display the specified number of rows. Note that if zero rows are specified, then the list will be created with a default of four rows. Also note that the number of visible rows in the list cannot be changed after it has been created. If the value of multipleMode is true, then the user can select multiple items from the list. If it is false, only one item at a time can be selected.

param
rows the number of items to show.
param
multipleMode if true, then multiple selections are allowed; otherwise, only one item can be selected at a time.
exception
HeadlessException if GraphicsEnvironment.isHeadless() returns true.
see
java.awt.GraphicsEnvironment#isHeadless


                                                                                                                                                                                     
           
        GraphicsEnvironment.checkHeadless();
	this.rows = (rows != 0) ? rows : DEFAULT_VISIBLE_ROWS;
	this.multipleMode = multipleMode;
    
Methods Summary
public voidadd(java.lang.String item)
Adds the specified item to the end of scrolling list.

param
item the item to be added
since
JDK1.1

	addItem(item);
    
public voidadd(java.lang.String item, int index)
Adds the specified item to the the scrolling list at the position indicated by the index. The index is zero-based. If the value of the index is less than zero, or if the value of the index is greater than or equal to the number of items in the list, then the item is added to the end of the list.

param
item the item to be added; if this parameter is null then the item is treated as an empty string, ""
param
index the position at which to add the item
since
JDK1.1

	addItem(item, index);
    
public synchronized voidaddActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this list. Action events occur when a user double-clicks on a list item or types Enter when the list has the keyboard focus.

If listener l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the action listener
see
#removeActionListener
see
#getActionListeners
see
java.awt.event.ActionEvent
see
java.awt.event.ActionListener
since
JDK1.1

	if (l == null) {
	    return;
	}
	actionListener = AWTEventMulticaster.add(actionListener, l);
        newEventsOnly = true;
    
public voidaddItem(java.lang.String item)

deprecated
replaced by add(String).

	addItem(item, -1);
    
public synchronized voidaddItem(java.lang.String item, int index)

deprecated
replaced by add(String, int).

	if (index < -1 || index >= items.size()) {
	    index = -1;
	}

        if (item == null) {
            item = "";
        }

	if (index == -1) {
	    items.addElement(item);
	} else {
	    items.insertElementAt(item, index);
	}

	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    peer.addItem(item, index);
	}
    
public synchronized voidaddItemListener(java.awt.event.ItemListener l)
Adds the specified item listener to receive item events from this list. Item events are sent in response to user input, but not in response to calls to select or deselect. If listener l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the item listener
see
#removeItemListener
see
#getItemListeners
see
#select
see
#deselect
see
java.awt.event.ItemEvent
see
java.awt.event.ItemListener
since
JDK1.1

	if (l == null) {
	    return;
	}
        itemListener = AWTEventMulticaster.add(itemListener, l);
        newEventsOnly = true;
    
public voidaddNotify()
Creates the peer for the list. The peer allows us to modify the list's appearance without changing its functionality.

        synchronized (getTreeLock()) {
	    if (peer == null)
	        peer = getToolkit().createList(this);
	    super.addNotify();
	}
    
public booleanallowsMultipleSelections()

deprecated
As of JDK version 1.1, replaced by isMultipleMode().

	return multipleMode;
    
public synchronized voidclear()

deprecated
As of JDK version 1.1, replaced by removeAll().

	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    peer.clear();
	}
	items = new Vector();
	selected = new int[0];
    
java.lang.StringconstructComponentName()
Construct a name for this component. Called by getName when the name is null.

        synchronized (getClass()) {
	    return base + nameCounter++;
	}
    
public intcountItems()

deprecated
As of JDK version 1.1, replaced by getItemCount().

	return items.size();
    
public voiddelItem(int position)

deprecated
replaced by remove(String) and remove(int).

	delItems(position, position);
    
public synchronized voiddelItems(int start, int end)

deprecated
As of JDK version 1.1, Not for public use in the future. This method is expected to be retained only as a package private method.

	for (int i = end; i >= start; i--) {
	    items.removeElementAt(i);
	}
	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    peer.delItems(start, end);
	}
    
public synchronized voiddeselect(int index)
Deselects the item at the specified index.

Note that passing out of range parameters is invalid, and will result in unspecified behavior.

If the item at the specified index is not selected, then the operation is ignored.

param
index the position of the item to deselect
see
#select
see
#getSelectedItem
see
#isIndexSelected

	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    peer.deselect(index);
	}

	for (int i = 0 ; i < selected.length ; i++) {
	    if (selected[i] == index) {
		int newsel[] = new int[selected.length - 1];
		System.arraycopy(selected, 0, newsel, 0, i);
		System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
		selected = newsel;
		return;
	    }
	}
    
booleaneventEnabled(java.awt.AWTEvent e)

        switch(e.id) {
          case ActionEvent.ACTION_PERFORMED:
            if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
                actionListener != null) {
                return true;
            }
            return false;
          case ItemEvent.ITEM_STATE_CHANGED:
            if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
                itemListener != null) {
                return true;
            }
            return false;
          default:
            break;
        }
        return super.eventEnabled(e);
    
public javax.accessibility.AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this List. For lists, the AccessibleContext takes the form of an AccessibleAWTList. A new AccessibleAWTList instance is created, if necessary.

return
an AccessibleAWTList that serves as the AccessibleContext of this List
since
1.3

        if (accessibleContext == null) {
            accessibleContext = new AccessibleAWTList();
        }
        return accessibleContext;
    
public synchronized java.awt.event.ActionListener[]getActionListeners()
Returns an array of all the action listeners registered on this list.

return
all of this list's ActionListeners or an empty array if no action listeners are currently registered
see
#addActionListener
see
#removeActionListener
see
java.awt.event.ActionEvent
see
java.awt.event.ActionListener
since
1.4

        return (ActionListener[])(getListeners(ActionListener.class));
    
public java.lang.StringgetItem(int index)
Gets the item associated with the specified index.

return
an item that is associated with the specified index
param
index the position of the item
see
#getItemCount

	return getItemImpl(index);
    
public intgetItemCount()
Gets the number of items in the list.

return
the number of items in the list
see
#getItem
since
JDK1.1

	return countItems();
    
final java.lang.StringgetItemImpl(int index)

	return (String)items.elementAt(index);
    
public synchronized java.awt.event.ItemListener[]getItemListeners()
Returns an array of all the item listeners registered on this list.

return
all of this list's ItemListeners or an empty array if no item listeners are currently registered
see
#addItemListener
see
#removeItemListener
see
java.awt.event.ItemEvent
see
java.awt.event.ItemListener
since
1.4

        return (ItemListener[])(getListeners(ItemListener.class)); 
    
public synchronized java.lang.String[]getItems()
Gets the items in the list.

return
a string array containing items of the list
see
#select
see
#deselect
see
#isIndexSelected
since
JDK1.1

	String itemCopies[] = new String[items.size()];
    	items.copyInto(itemCopies);
	return itemCopies;
    
public T[]getListeners(java.lang.Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this List. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a List l for its item listeners with the following code:

ItemListener[] ils = (ItemListener[])(l.getListeners(ItemListener.class));
If no such listeners exist, this method returns an empty array.

param
listenerType the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
return
an array of all objects registered as FooListeners on this list, or an empty array if no such listeners have been added
exception
ClassCastException if listenerType doesn't specify a class or interface that implements java.util.EventListener
see
#getItemListeners
since
1.3

 
	EventListener l = null; 
	if  (listenerType == ActionListener.class) { 
	    l = actionListener;
	} else if  (listenerType == ItemListener.class) { 
	    l = itemListener;
	} else {
	    return super.getListeners(listenerType);
	}
	return AWTEventMulticaster.getListeners(l, listenerType);
    
public java.awt.DimensiongetMinimumSize(int rows)
Gets the minumum dimensions for a list with the specified number of rows.

param
rows number of rows in the list
return
the minimum dimensions for displaying this scrolling list given that the specified number of rows must be visible
see
java.awt.Component#getMinimumSize
since
JDK1.1

	return minimumSize(rows);
    
public java.awt.DimensiongetMinimumSize()
Determines the minimum size of this scrolling list.

return
the minimum dimensions needed to display this scrolling list
see
java.awt.Component#getMinimumSize()
since
JDK1.1

	return minimumSize();
    
public java.awt.DimensiongetPreferredSize(int rows)
Gets the preferred dimensions for a list with the specified number of rows.

param
rows number of rows in the list
return
the preferred dimensions for displaying this scrolling list given that the specified number of rows must be visible
see
java.awt.Component#getPreferredSize
since
JDK1.1

	return preferredSize(rows);
    
public java.awt.DimensiongetPreferredSize()
Gets the preferred size of this scrolling list.

return
the preferred dimensions for displaying this scrolling list
see
java.awt.Component#getPreferredSize
since
JDK1.1

	return preferredSize();
    
public intgetRows()
Gets the number of visible lines in this list. Note that once the List has been created, this number will never change.

return
the number of visible lines in this scrolling list

	return rows;
    
public synchronized intgetSelectedIndex()
Gets the index of the selected item on the list,

return
the index of the selected item; if no item is selected, or if multiple items are selected, -1 is returned.
see
#select
see
#deselect
see
#isIndexSelected

	int sel[] = getSelectedIndexes();
	return (sel.length == 1) ? sel[0] : -1;
    
public synchronized int[]getSelectedIndexes()
Gets the selected indexes on the list.

return
an array of the selected indexes on this scrolling list; if no item is selected, a zero-length array is returned.
see
#select
see
#deselect
see
#isIndexSelected

	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    selected = ((ListPeer)peer).getSelectedIndexes();
	}
	return (int[])selected.clone();
    
public synchronized java.lang.StringgetSelectedItem()
Gets the selected item on this scrolling list.

return
the selected item on the list; if no item is selected, or if multiple items are selected, null is returned.
see
#select
see
#deselect
see
#isIndexSelected

	int index = getSelectedIndex();
	return (index < 0) ? null : getItem(index);
    
public synchronized java.lang.String[]getSelectedItems()
Gets the selected items on this scrolling list.

return
an array of the selected items on this scrolling list; if no item is selected, a zero-length array is returned.
see
#select
see
#deselect
see
#isIndexSelected

	int sel[] = getSelectedIndexes();
	String str[] = new String[sel.length];
	for (int i = 0 ; i < sel.length ; i++) {
	    str[i] = getItem(sel[i]);
	}
	return str;
    
public java.lang.Object[]getSelectedObjects()
Gets the selected items on this scrolling list in an array of Objects.

return
an array of Objects representing the selected items on this scrolling list; if no item is selected, a zero-length array is returned.
see
#getSelectedItems
see
ItemSelectable

        return getSelectedItems();
    
public intgetVisibleIndex()
Gets the index of the item that was last made visible by the method makeVisible.

return
the index of the item that was last made visible
see
#makeVisible

	return visibleIndex;
    
public booleanisIndexSelected(int index)
Determines if the specified item in this scrolling list is selected.

param
index the item to be checked
return
true if the specified item has been selected; false otherwise
see
#select
see
#deselect
since
JDK1.1

	return isSelected(index);
    
public booleanisMultipleMode()
Determines whether this list allows multiple selections.

return
true if this list allows multiple selections; otherwise, false
see
#setMultipleMode
since
JDK1.1

	return allowsMultipleSelections();
    
public booleanisSelected(int index)

deprecated
As of JDK version 1.1, replaced by isIndexSelected(int).

	int sel[] = getSelectedIndexes();
	for (int i = 0 ; i < sel.length ; i++) {
	    if (sel[i] == index) {
		return true;
	    }
	}
	return false;
    
public synchronized voidmakeVisible(int index)
Makes the item at the specified index visible.

param
index the position of the item
see
#getVisibleIndex

	visibleIndex = index;
	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	    peer.makeVisible(index);
	}
    
public java.awt.DimensionminimumSize(int rows)

deprecated
As of JDK version 1.1, replaced by getMinimumSize(int).

        synchronized (getTreeLock()) {
	    ListPeer peer = (ListPeer)this.peer;
	    return (peer != null) ?
		       peer.minimumSize(rows) :
		       super.minimumSize();
        }
    
public java.awt.DimensionminimumSize()

deprecated
As of JDK version 1.1, replaced by getMinimumSize().

        synchronized (getTreeLock()) {
	    return (rows > 0) ? minimumSize(rows) : super.minimumSize();
        }
    
protected java.lang.StringparamString()
Returns the parameter string representing the state of this scrolling list. This string is useful for debugging.

return
the parameter string of this scrolling list

	return super.paramString() + ",selected=" + getSelectedItem();
    
public java.awt.DimensionpreferredSize(int rows)

deprecated
As of JDK version 1.1, replaced by getPreferredSize(int).

        synchronized (getTreeLock()) {
	    ListPeer peer = (ListPeer)this.peer;
	    return (peer != null) ?
		       peer.preferredSize(rows) :
		       super.preferredSize();
        }
    
public java.awt.DimensionpreferredSize()

deprecated
As of JDK version 1.1, replaced by getPreferredSize().

        synchronized (getTreeLock()) {
	    return (rows > 0) ?
		       preferredSize(rows) :
		       super.preferredSize();
        }
    
protected voidprocessActionEvent(java.awt.event.ActionEvent e)
Processes action events occurring on this component by dispatching them to any registered ActionListener objects.

This method is not called unless action events are enabled for this component. Action events are enabled when one of the following occurs:

  • An ActionListener object is registered via addActionListener.
  • Action events are enabled via enableEvents.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

param
e the action event
see
java.awt.event.ActionEvent
see
java.awt.event.ActionListener
see
#addActionListener
see
java.awt.Component#enableEvents
since
JDK1.1

        ActionListener listener = actionListener;
        if (listener != null) {
            listener.actionPerformed(e);
        }
    
protected voidprocessEvent(java.awt.AWTEvent e)
Processes events on this scrolling list. If an event is an instance of ItemEvent, it invokes the processItemEvent method. Else, if the event is an instance of ActionEvent, it invokes processActionEvent. If the event is not an item event or an action event, it invokes processEvent on the superclass.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

param
e the event
see
java.awt.event.ActionEvent
see
java.awt.event.ItemEvent
see
#processActionEvent
see
#processItemEvent
since
JDK1.1

        if (e instanceof ItemEvent) {
            processItemEvent((ItemEvent)e);
            return;
        } else if (e instanceof ActionEvent) {
            processActionEvent((ActionEvent)e);
            return;
        }
	super.processEvent(e);
    
protected voidprocessItemEvent(java.awt.event.ItemEvent e)
Processes item events occurring on this list by dispatching them to any registered ItemListener objects.

This method is not called unless item events are enabled for this component. Item events are enabled when one of the following occurs:

  • An ItemListener object is registered via addItemListener.
  • Item events are enabled via enableEvents.

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

param
e the item event
see
java.awt.event.ItemEvent
see
java.awt.event.ItemListener
see
#addItemListener
see
java.awt.Component#enableEvents
since
JDK1.1

        ItemListener listener = itemListener;
        if (listener != null) {
            listener.itemStateChanged(e);
        }
    
private voidreadObject(java.io.ObjectInputStream s)
Reads the ObjectInputStream and if it isn't null adds a listener to receive both item events and action events (as specified by the key stored in the stream) fired by the List. Unrecognized keys or values will be ignored.

param
s the ObjectInputStream to write
exception
HeadlessException if GraphicsEnvironment.isHeadless returns true
see
#removeItemListener(ItemListener)
see
#addItemListener(ItemListener)
see
java.awt.GraphicsEnvironment#isHeadless
see
#writeObject(ObjectOutputStream)

      GraphicsEnvironment.checkHeadless();
      s.defaultReadObject();

      Object keyOrNull;
      while(null != (keyOrNull = s.readObject())) {
	String key = ((String)keyOrNull).intern();

	if (itemListenerK == key)
	  addItemListener((ItemListener)(s.readObject()));

	else if (actionListenerK == key)
	  addActionListener((ActionListener)(s.readObject()));

	else // skip value for unrecognized key
	  s.readObject();
      }
    
public synchronized voidremove(java.lang.String item)
Removes the first occurrence of an item from the list. If the specified item is selected, and is the only selected item in the list, the list is set to have no selection.

param
item the item to remove from the list
exception
IllegalArgumentException if the item doesn't exist in the list
since
JDK1.1

    	int index = items.indexOf(item);
    	if (index < 0) {
	    throw new IllegalArgumentException("item " + item +
					       " not found in list");
	} else {
	    remove(index);
	}
    
public voidremove(int position)
Removes the item at the specified position from this scrolling list. If the item with the specified position is selected, and is the only selected item in the list, the list is set to have no selection.

param
position the index of the item to delete
see
#add(String, int)
since
JDK1.1
exception
ArrayIndexOutOfBoundsException if the position is less than 0 or greater than getItemCount()-1

	delItem(position);
    
public synchronized voidremoveActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so that it no longer receives action events from this list. Action events occur when a user double-clicks on a list item. If listener l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the action listener
see
#addActionListener
see
#getActionListeners
see
java.awt.event.ActionEvent
see
java.awt.event.ActionListener
since
JDK1.1

	if (l == null) {
	    return;
	}
	actionListener = AWTEventMulticaster.remove(actionListener, l);
    
public voidremoveAll()
Removes all items from this list.

see
#remove
see
#delItems
since
JDK1.1

	clear();
    
public synchronized voidremoveItemListener(java.awt.event.ItemListener l)
Removes the specified item listener so that it no longer receives item events from this list. If listener l is null, no exception is thrown and no action is performed.

Refer to AWT Threading Issues for details on AWT's threading model.

param
l the item listener
see
#addItemListener
see
#getItemListeners
see
java.awt.event.ItemEvent
see
java.awt.event.ItemListener
since
JDK1.1

	if (l == null) {
	    return;
	}
        itemListener = AWTEventMulticaster.remove(itemListener, l);
    
public voidremoveNotify()
Removes the peer for this list. The peer allows us to modify the list's appearance without changing its functionality.

    	synchronized (getTreeLock()) {
	    ListPeer peer = (ListPeer)this.peer;
	    if (peer != null) {
		selected = peer.getSelectedIndexes();
	    }
	    super.removeNotify();
	}
    
public synchronized voidreplaceItem(java.lang.String newValue, int index)
Replaces the item at the specified index in the scrolling list with the new string.

param
newValue a new string to replace an existing item
param
index the position of the item to replace
exception
ArrayIndexOutOfBoundsException if index is out of range

	remove(index);
	add(newValue, index);
    
public voidselect(int index)
Selects the item at the specified index in the scrolling list.

Note that passing out of range parameters is invalid, and will result in unspecified behavior.

Note that this method should be primarily used to initially select an item in this component. Programmatically calling this method will not trigger an ItemEvent. The only way to trigger an ItemEvent is by user interaction.

param
index the position of the item to select
see
#getSelectedItem
see
#deselect
see
#isIndexSelected

        // Bug #4059614: select can't be synchronized while calling the peer, 
        // because it is called from the Window Thread.  It is sufficient to 
        // synchronize the code that manipulates 'selected' except for the 
        // case where the peer changes.  To handle this case, we simply 
        // repeat the selection process. 
         
        ListPeer peer; 
        do { 
            peer = (ListPeer)this.peer; 
            if (peer != null) { 
                peer.select(index); 
                return; 
            } 
             
            synchronized(this) 
            { 
                boolean alreadySelected = false; 
 
                for (int i = 0 ; i < selected.length ; i++) { 
                    if (selected[i] == index) { 
                        alreadySelected = true; 
                        break; 
                    } 
                } 
 
                if (!alreadySelected) { 
                    if (!multipleMode) { 
                        selected = new int[1]; 
                        selected[0] = index; 
                    } else { 
                        int newsel[] = new int[selected.length + 1]; 
                        System.arraycopy(selected, 0, newsel, 0, 
                                         selected.length); 
                        newsel[selected.length] = index; 
                        selected = newsel; 
                    } 
                } 
            } 
        } while (peer != this.peer); 
    
public voidsetMultipleMode(boolean b)
Sets the flag that determines whether this list allows multiple selections. When the selection mode is changed from multiple-selection to single-selection, the selected items change as follows: If a selected item has the location cursor, only that item will remain selected. If no selected item has the location cursor, all items will be deselected.

param
b if true then multiple selections are allowed; otherwise, only one item from the list can be selected at once
see
#isMultipleMode
since
JDK1.1

    	setMultipleSelections(b);
    
public synchronized voidsetMultipleSelections(boolean b)

deprecated
As of JDK version 1.1, replaced by setMultipleMode(boolean).

	if (b != multipleMode) {
	    multipleMode = b;
	    ListPeer peer = (ListPeer)this.peer;
	    if (peer != null) {
		peer.setMultipleSelections(b);
	    }
	}
    
private voidwriteObject(java.io.ObjectOutputStream s)
Writes default serializable fields to stream. Writes a list of serializable ItemListeners and ActionListeners as optional data. The non-serializable listeners are detected and no attempt is made to serialize them.

serialData
null terminated sequence of 0 or more pairs; the pair consists of a String and an Object; the String indicates the type of object and is one of the following: itemListenerK indicating an ItemListener object; actionListenerK indicating an ActionListener object
param
s the ObjectOutputStream to write
see
AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
see
java.awt.Component#itemListenerK
see
java.awt.Component#actionListenerK
see
#readObject(ObjectInputStream)


                                                                                                             
       
       
    
      synchronized (this) {
	ListPeer peer = (ListPeer)this.peer;
	if (peer != null) {
	  selected = peer.getSelectedIndexes();
	}
      }
      s.defaultWriteObject();

      AWTEventMulticaster.save(s, itemListenerK, itemListener);
      AWTEventMulticaster.save(s, actionListenerK, actionListener);
      s.writeObject(null);