The List is a Component that provides a scrollable list of choices to select from. A List can be in one of two modes: single selection mode, in which only one item may be selected at a time; and multiple selection mode, in which several items may be selected at one time. A list does not necessarily display all of the choices at one time; one of the constructors lets you specify the number of choices to display simultaneously. Although the changes in 1.1 are extensive, almost all of them can be boiled down to (1) using the 1.1 event model, and (2) standardizing method names (e.g. set/get pairs).
public class java.awt.List extends java.awt.Component implements java.awt.ItemSelectable { // Constructors public List(); public List (int rows); public List (int rows, boolean multipleSelections); // Instance Methods public void add (String item); public synchronized void add (String item, int index); public void addActionListener (ActionListener l); public void addItem (String item); public synchronized void addItem (String item, int index); public void addItemListener (ItemListener l); public void addNotify(); public boolean allowsMultipleSelections(); public synchronized void clear(); public int countItems(); public synchronized void delItem (int position); public synchronized void delItems (int start, int end); public synchronized void deselect (int index); public String getItem (int index); public int getItemCount(); public synchronized String[] getItems(); public Dimension getMinimumSize(); public Dimension getMinimumSize (int rows); public Dimension getPreferredSize(); public Dimension getPreferredSize (int rows); public int getRows(); public synchronized int getSelectedIndex(); public synchronized int[] getSelectedIndexes(); public synchronized String getSelectedItem(); public synchronized String[] getSelectedItems(); public Object[] getSelectedObjects(); public int getVisibleIndex(); public boolean isIndexSelected(int index); public boolean isMultipleMode(); public boolean isSelected (int index); public synchronized void makeVisible (int index); public Dimension minimumSize(); public Dimension minimumSize (int rows); public Dimension preferredSize(); public Dimension preferredSize (int rows); public synchronized void remove (int position); public synchronized void remove (String item); public void removeActionListener (ActionListener l); public synchronized void removeAll(); public void removeItemListener (ItemListener l); public void removeNotify(); public synchronized void replaceItem (String newItem, int index); public synchronized void select (int position); public synchronized void setMultipleMode (boolean b); public synchronized void setMultipleSelections (boolean value); // Protected Instance Methods protected String paramString(); protected void processActionEvent (ActionEvent e); protected void processEvent (AWTEvent e); protected void processItemEvent (ItemEvent e); }
Constructs a List object in single-selection mode.
Requested number of rows to display.
Constructs a List object with the specified number of rows, in single-selection mode.
Requested number of rows to display.
true to allow multiple selections; false to select one item at a time.
Constructs a List object.
Text for entry to add.
Adds a new entry to the available choices.
Text for entry to add.
Position at which to add entry; the first entry has an index of zero.
Adds a new entry to the available choices at the designated position.
An object that implements the ActionListener interface.
Add a listener for the action event.
Text for entry to add.
Replaced by add(String).
Text for entry to add.
Position at which to add entry; the first entry has an index of zero.
Replaced by add(String, int).
The listener to be added.
ItemSelectable.addItemListener(ItemListener l)
Adds a listener for the ItemEvent objects this List fires off.
Component.addNotify()
Creates List's peer.
true if multi-selection active, false otherwise. Replaced by isMultipleMode().
Clears all the entries out of the List. Replaced by removeAll().
Number of items in the List. Replaced by getItemCount().
Position of item to delete.
Removes a single entry from the List. Replaced by remove(int) and remove(String).
Starting position of entries to delete.
Ending position of entries to delete.
Removes a set of entries from the List.
Position to deselect.
Deselects the entry at the designated position, if selected.
Position of entry to get.
If index is invalid.
String for entry at given position.
Number of items in the List.
The string items in the List.
The minimum dimensions of the List.
Number of rows within List to size.
The minimum dimensions of a List of the given size.
The preferred dimensions of the List.
Number of rows within List to size.
The preferred dimensions of a List of the given size.
Returns number of rows requested to be displayed in List.
Position of currently selected entry, or -1 if nothing is selected, or if multiple entries are selected.
An array whose elements are the indices of the currently selected entries.
Currently selected entry as a String, or null if nothing is selected, or if multiple entries are selected.
An array of strings whose elements are the labels of the currently selected entries.
ItemSelectable.getSelectedObjects()
An array of strings whose elements are the labels of the currently selected entries.
The last index from a call to makeVisible().
Position to check.
true if index selected, false otherwise.
Checks to see if a particular entry is currently selected.
true if multiple selection is allowed, false otherwise.
Position to check.
true if index selected, false otherwise.
Checks to see if a particular entry is currently selected. Replaced by isIndexSelected(int).
Position to make visible on screen.
Ensures an item is displayed on the screen.
The minimum dimensions of the List. Replaced by getMinimumSize().
Number of rows within List to size.
The minimum dimensions of a List of the given size. Replaced by getMinimumSize(int).
The preferred dimensions of the List. Replaced by getPreferredSize().
Number of rows within List to size.
The preferred dimensions of a List of the given size. Replaced by getPreferredSize(int).
Position of item to remove.
Removes a single entry from the List.
Item to remove.
If item is not in the List.
Removes a single entry from the List.
One of this List's ActionListeners.
Remove an action event listener.
Removes all items from the List.
The listener to be removed.
ItemSelectable.removeItemListener (ItemListener l)
Removes the specified ItemListener so it will not receive ItemEvent objects from this List.
Destroys the peer of the List.
Label for entry to add.
Position of entry to replace.
Replaces the contents at a particular position with a new entry.
Position to make selected entry.
Makes the given entry the selected one for the List.
true to enable multiple selections; false to disable multiple selections.
Changes List's selection mode based upon flag.
true to enable multiple selections; false to disable multiple selections.
Changes List's selection mode based upon flag. Replaced by setMultipleMode(boolean).
String with current settings of List.
Component.paramString()
Helper method for toString() to generate string of current settings.
The action event to process.
Action events are passed to this method for processing. Normally, this method is called by processEvent().
The event to process.
Low-level AWTEvents are passed to this method for processing.
The item event to process.
Item events are passed to this method for processing. Normally, this method is called by processEvent().
Component, Dimension, ItemSelectable, String