List Methods

You create a new List with one of these three constructors:

  public List()
  public List(int numLines)
  public List(int numLines, boolean allowMultipleSelections) 
For example,

List l = new List(8, true);

numLines is the number of items you want to be visible in the scrolling list. It is not necessarily the same as the number of items in the list which is limited only by available memory. allowMultipleSelections says whether the user is allowed to select more than one item at once (typically by Shift-clicking).

The following methods add items at the end of the list:

public void add(String item)
public void addItem(String item)
These two methods add items at the specified position in the list.

public synchronized void add(String item, int index)
public synchronized void addItem(String item, int index)
The following methods remove items from the List:

  public synchronized void removeAll()
  public synchronized void remove(String item)
  public synchronized void remove(int position)
  public synchronized void delItem(int position)
These methods allow you to retrive particular items from the List:

  public int getItemCount()
  public String getItem(int index)
  public synchronized String[] getItems()
You ran also replace a particular item:

  public synchronized void replaceItem(String newValue, int index)
These methods allow you to determine which item the user has selected:

  public synchronized int getSelectedIndex()
  public synchronized int[] getSelectedIndexes()
  public synchronized String getSelectedItem()
  public synchronized String[] getSelectedItems()
  public Object[] getSelectedObjects()
If a list allows multiple selections, you should use the plural forms of the above methods. You can determine whether multiple selections are allowed with isMultipleMode() and change it with setMultipleMode().

  public boolean isMultipleMode()
  public synchronized void setMultipleMode(boolean b)
These methods allow you to manipulate the selection:

  public synchronized void select(int index)
  public synchronized void deselect(int index)
  public boolean isIndexSelected(int index)
These two methods determine whether an item at a particular index is currently visible in the List box:

  public int getVisibleIndex()
  public synchronized void makeVisible(int index)

Previous | Next | Top
Last Modified November 15, 1999
Copyright 1997, 1999 Elliotte Rusty Harold
elharo@metalab.unc.edu