List (Java 2 Platform SE 5.0) (original) (raw)


java.awt

Class List

java.lang.Object extended by java.awt.Component extended by java.awt.List

All Implemented Interfaces:

ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible


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 tolist = 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 implementItemListener 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.

Since:

JDK1.0

See Also:

ItemEvent, ItemListener, ActionEvent, ActionListener, Serialized Form


Nested Class Summary
protected class List.AccessibleAWTList This class implements accessibility support for the List class.
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Field Summary
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor Summary
List() Creates a new scrolling list.
List(int rows) Creates a new scrolling list initialized with the specified number of visible lines.
[List](../../java/awt/List.html#List%28int, boolean%29)(int rows, boolean multipleMode) Creates a new scrolling list initialized to display the specified number of rows.
Method Summary
void add(String item) Adds the specified item to the end of scrolling list.
void [add](../../java/awt/List.html#add%28java.lang.String, int%29)(String item, int index) Adds the specified item to the the scrolling list at the position indicated by the index.
void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this list.
void addItem(String item) Deprecated. replaced by add(String).
void [addItem](../../java/awt/List.html#addItem%28java.lang.String, int%29)(String item, int index) Deprecated. replaced by add(String, int).
void addItemListener(ItemListener l) Adds the specified item listener to receive item events from this list.
void addNotify() Creates the peer for the list.
boolean allowsMultipleSelections() Deprecated. As of JDK version 1.1, replaced by isMultipleMode().
void clear() Deprecated. As of JDK version 1.1, replaced by removeAll().
int countItems() Deprecated. As of JDK version 1.1, replaced by getItemCount().
void delItem(int position) Deprecated. replaced by remove(String) and remove(int).
void [delItems](../../java/awt/List.html#delItems%28int, int%29)(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.
void deselect(int index) Deselects the item at the specified index.
AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with this List.
ActionListener[] getActionListeners() Returns an array of all the action listeners registered on this list.
String getItem(int index) Gets the item associated with the specified index.
int getItemCount() Gets the number of items in the list.
ItemListener[] getItemListeners() Returns an array of all the item listeners registered on this list.
String[] getItems() Gets the items in the list.
<T extends EventListener> T[] getListeners(Class listenerType) Returns an array of all the objects currently registered as _Foo_Listeners upon this List.
Dimension getMinimumSize() Determines the minimum size of this scrolling list.
Dimension getMinimumSize(int rows) Gets the minumum dimensions for a list with the specified number of rows.
Dimension getPreferredSize() Gets the preferred size of this scrolling list.
Dimension getPreferredSize(int rows) Gets the preferred dimensions for a list with the specified number of rows.
int getRows() Gets the number of visible lines in this list.
int getSelectedIndex() Gets the index of the selected item on the list,
int[] getSelectedIndexes() Gets the selected indexes on the list.
String getSelectedItem() Gets the selected item on this scrolling list.
String[] getSelectedItems() Gets the selected items on this scrolling list.
Object[] getSelectedObjects() Gets the selected items on this scrolling list in an array of Objects.
int getVisibleIndex() Gets the index of the item that was last made visible by the method makeVisible.
boolean isIndexSelected(int index) Determines if the specified item in this scrolling list is selected.
boolean isMultipleMode() Determines whether this list allows multiple selections.
boolean isSelected(int index) Deprecated. As of JDK version 1.1, replaced by isIndexSelected(int).
void makeVisible(int index) Makes the item at the specified index visible.
Dimension minimumSize() Deprecated. As of JDK version 1.1, replaced by getMinimumSize().
Dimension minimumSize(int rows) Deprecated. As of JDK version 1.1, replaced by getMinimumSize(int).
protected String paramString() Returns the parameter string representing the state of this scrolling list.
Dimension preferredSize() Deprecated. As of JDK version 1.1, replaced by getPreferredSize().
Dimension preferredSize(int rows) Deprecated. As of JDK version 1.1, replaced by getPreferredSize(int).
protected void processActionEvent(ActionEvent e) Processes action events occurring on this component by dispatching them to any registeredActionListener objects.
protected void processEvent(AWTEvent e) Processes events on this scrolling list.
protected void processItemEvent(ItemEvent e) Processes item events occurring on this list by dispatching them to any registeredItemListener objects.
void remove(int position) Removes the item at the specified position from this scrolling list.
void remove(String item) Removes the first occurrence of an item from the list.
void removeActionListener(ActionListener l) Removes the specified action listener so that it no longer receives action events from this list.
void removeAll() Removes all items from this list.
void removeItemListener(ItemListener l) Removes the specified item listener so that it no longer receives item events from this list.
void removeNotify() Removes the peer for this list.
void [replaceItem](../../java/awt/List.html#replaceItem%28java.lang.String, int%29)(String newValue, int index) Replaces the item at the specified index in the scrolling list with the new string.
void select(int index) Selects the item at the specified index in the scrolling list.
void setMultipleMode(boolean b) Sets the flag that determines whether this list allows multiple selections.
void setMultipleSelections(boolean b) Deprecated. As of JDK version 1.1, replaced by setMultipleMode(boolean).
Methods inherited from class java.awt.Component
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Component.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), [contains](../../java/awt/Component.html#contains%28int, int%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, int, int%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, [getComponentAt](../../java/awt/Component.html#getComponentAt%28int, int%29), getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), layout, list, list, [list](../../java/awt/Component.html#list%28java.io.PrintStream, int%29), list, [list](../../java/awt/Component.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Component.html#locate%28int, int%29), location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paint, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, [repaint](../../java/awt/Component.html#repaint%28long, int, int, int, int%29), requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, [reshape](../../java/awt/Component.html#reshape%28int, int, int, int%29), resize, [resize](../../java/awt/Component.html#resize%28int, int%29), setBackground, [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, [setFocusTraversalKeys](../../java/awt/Component.html#setFocusTraversalKeys%28int, java.util.Set%29), setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29)
Constructor Detail

List

public List() throws HeadlessException

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 forList(0, false). Also note that the number of visible lines in the list cannot be changed after it has been created.

Throws:

[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt") - if GraphicsEnvironment.isHeadless() returns true.

See Also:

GraphicsEnvironment.isHeadless()


List

public List(int rows) throws HeadlessException

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 forList(rows, false). Also note that the number of visible rows in the list cannot be changed after it has been created.

Parameters:

rows - the number of items to show.

Throws:

[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt") - if GraphicsEnvironment.isHeadless() returns true.

Since:

JDK1.1

See Also:

GraphicsEnvironment.isHeadless()


List

public List(int rows, boolean multipleMode) throws HeadlessException

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 istrue, then the user can select multiple items from the list. If it is false, only one item at a time can be selected.

Parameters:

rows - the number of items to show.

multipleMode - if true, then multiple selections are allowed; otherwise, only one item can be selected at a time.

Throws:

[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt") - if GraphicsEnvironment.isHeadless() returns true.

See Also:

GraphicsEnvironment.isHeadless()

Method Detail

addNotify

public void addNotify()

Creates the peer for the list. The peer allows us to modify the list's appearance without changing its functionality.

Overrides:

[addNotify](../../java/awt/Component.html#addNotify%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

See Also:

Component.isDisplayable(), Component.removeNotify()


removeNotify

public void removeNotify()

Removes the peer for this list. The peer allows us to modify the list's appearance without changing its functionality.

Overrides:

[removeNotify](../../java/awt/Component.html#removeNotify%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

See Also:

Component.isDisplayable(), Component.addNotify()


getItemCount

public int getItemCount()

Gets the number of items in the list.

Returns:

the number of items in the list

Since:

JDK1.1

See Also:

getItem(int)


countItems

@Deprecated public int countItems()

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


getItem

public String getItem(int index)

Gets the item associated with the specified index.

Parameters:

index - the position of the item

Returns:

an item that is associated with the specified index

See Also:

getItemCount()


getItems

public String[] getItems()

Gets the items in the list.

Returns:

a string array containing items of the list

Since:

JDK1.1

See Also:

select(int), deselect(int), isIndexSelected(int)


add

public void add(String item)

Adds the specified item to the end of scrolling list.

Parameters:

item - the item to be added

Since:

JDK1.1


addItem

@Deprecated public void addItem(String item)

Deprecated. replaced by add(String).


add

public void add(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.

Parameters:

item - the item to be added; if this parameter is null then the item is treated as an empty string, ""

index - the position at which to add the item

Since:

JDK1.1


addItem

@Deprecated public void addItem(String item, int index)

Deprecated. replaced by add(String, int).


replaceItem

public void replaceItem(String newValue, int index)

Replaces the item at the specified index in the scrolling list with the new string.

Parameters:

newValue - a new string to replace an existing item

index - the position of the item to replace

Throws:

[ArrayIndexOutOfBoundsException](../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang") - if index is out of range


removeAll

public void removeAll()

Removes all items from this list.

Since:

JDK1.1

See Also:

remove(java.lang.String), [delItems(int, int)](../../java/awt/List.html#delItems%28int, int%29)


clear

@Deprecated public void clear()

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


remove

public void remove(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.

Parameters:

item - the item to remove from the list

Throws:

[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang") - if the item doesn't exist in the list

Since:

JDK1.1


remove

public void remove(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.

Parameters:

position - the index of the item to delete

Throws:

[ArrayIndexOutOfBoundsException](../../java/lang/ArrayIndexOutOfBoundsException.html "class in java.lang") - if the position is less than 0 or greater than getItemCount()-1

Since:

JDK1.1

See Also:

[add(String, int)](../../java/awt/List.html#add%28java.lang.String, int%29)


delItem

@Deprecated public void delItem(int position)

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


getSelectedIndex

public int getSelectedIndex()

Gets the index of the selected item on the list,

Returns:

the index of the selected item; if no item is selected, or if multiple items are selected, -1 is returned.

See Also:

select(int), deselect(int), isIndexSelected(int)


getSelectedIndexes

public int[] getSelectedIndexes()

Gets the selected indexes on the list.

Returns:

an array of the selected indexes on this scrolling list; if no item is selected, a zero-length array is returned.

See Also:

select(int), deselect(int), isIndexSelected(int)


getSelectedItem

public String getSelectedItem()

Gets the selected item on this scrolling list.

Returns:

the selected item on the list; if no item is selected, or if multiple items are selected, null is returned.

See Also:

select(int), deselect(int), isIndexSelected(int)


getSelectedItems

public String[] getSelectedItems()

Gets the selected items on this scrolling list.

Returns:

an array of the selected items on this scrolling list; if no item is selected, a zero-length array is returned.

See Also:

select(int), deselect(int), isIndexSelected(int)


getSelectedObjects

public Object[] getSelectedObjects()

Gets the selected items on this scrolling list in an array of Objects.

Specified by:

[getSelectedObjects](../../java/awt/ItemSelectable.html#getSelectedObjects%28%29) in interface [ItemSelectable](../../java/awt/ItemSelectable.html "interface in java.awt")

Returns:

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

See Also:

getSelectedItems(), ItemSelectable


select

public void select(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 anItemEvent is by user interaction.

Parameters:

index - the position of the item to select

See Also:

getSelectedItem(), deselect(int), isIndexSelected(int)


deselect

public void deselect(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.

Parameters:

index - the position of the item to deselect

See Also:

select(int), getSelectedItem(), isIndexSelected(int)


isIndexSelected

public boolean isIndexSelected(int index)

Determines if the specified item in this scrolling list is selected.

Parameters:

index - the item to be checked

Returns:

true if the specified item has been selected; false otherwise

Since:

JDK1.1

See Also:

select(int), deselect(int)


isSelected

@Deprecated public boolean isSelected(int index)

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


getRows

public int getRows()

Gets the number of visible lines in this list. Note that once the List has been created, this number will never change.

Returns:

the number of visible lines in this scrolling list


isMultipleMode

public boolean isMultipleMode()

Determines whether this list allows multiple selections.

Returns:

true if this list allows multiple selections; otherwise, false

Since:

JDK1.1

See Also:

setMultipleMode(boolean)


allowsMultipleSelections

@Deprecated public boolean allowsMultipleSelections()

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


setMultipleMode

public void setMultipleMode(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.

Parameters:

b - if true then multiple selections are allowed; otherwise, only one item from the list can be selected at once

Since:

JDK1.1

See Also:

isMultipleMode()


setMultipleSelections

@Deprecated public void setMultipleSelections(boolean b)

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


getVisibleIndex

public int getVisibleIndex()

Gets the index of the item that was last made visible by the method makeVisible.

Returns:

the index of the item that was last made visible

See Also:

makeVisible(int)


makeVisible

public void makeVisible(int index)

Makes the item at the specified index visible.

Parameters:

index - the position of the item

See Also:

getVisibleIndex()


getPreferredSize

public Dimension getPreferredSize(int rows)

Gets the preferred dimensions for a list with the specified number of rows.

Parameters:

rows - number of rows in the list

Returns:

the preferred dimensions for displaying this scrolling list given that the specified number of rows must be visible

Since:

JDK1.1

See Also:

Component.getPreferredSize()


preferredSize

@Deprecated public Dimension preferredSize(int rows)

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


getPreferredSize

public Dimension getPreferredSize()

Gets the preferred size of this scrolling list.

Overrides:

[getPreferredSize](../../java/awt/Component.html#getPreferredSize%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Returns:

the preferred dimensions for displaying this scrolling list

Since:

JDK1.1

See Also:

Component.getPreferredSize()


preferredSize

@Deprecated public Dimension preferredSize()

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

Overrides:

[preferredSize](../../java/awt/Component.html#preferredSize%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")


getMinimumSize

public Dimension getMinimumSize(int rows)

Gets the minumum dimensions for a list with the specified number of rows.

Parameters:

rows - number of rows in the list

Returns:

the minimum dimensions for displaying this scrolling list given that the specified number of rows must be visible

Since:

JDK1.1

See Also:

Component.getMinimumSize()


minimumSize

@Deprecated public Dimension minimumSize(int rows)

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


getMinimumSize

public Dimension getMinimumSize()

Determines the minimum size of this scrolling list.

Overrides:

[getMinimumSize](../../java/awt/Component.html#getMinimumSize%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Returns:

the minimum dimensions needed to display this scrolling list

Since:

JDK1.1

See Also:

Component.getMinimumSize()


minimumSize

@Deprecated public Dimension minimumSize()

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

Overrides:

[minimumSize](../../java/awt/Component.html#minimumSize%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")


addItemListener

public void addItemListener(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.

Specified by:

[addItemListener](../../java/awt/ItemSelectable.html#addItemListener%28java.awt.event.ItemListener%29) in interface [ItemSelectable](../../java/awt/ItemSelectable.html "interface in java.awt")

Parameters:

l - the item listener

Since:

JDK1.1

See Also:

removeItemListener(java.awt.event.ItemListener), getItemListeners(), select(int), deselect(int), ItemEvent, ItemListener


removeItemListener

public void removeItemListener(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.

Specified by:

[removeItemListener](../../java/awt/ItemSelectable.html#removeItemListener%28java.awt.event.ItemListener%29) in interface [ItemSelectable](../../java/awt/ItemSelectable.html "interface in java.awt")

Parameters:

l - the item listener

Since:

JDK1.1

See Also:

addItemListener(java.awt.event.ItemListener), getItemListeners(), ItemEvent, ItemListener


getItemListeners

public ItemListener[] getItemListeners()

Returns an array of all the item listeners registered on this list.

Returns:

all of this list's ItemListeners or an empty array if no item listeners are currently registered

Since:

1.4

See Also:

addItemListener(java.awt.event.ItemListener), removeItemListener(java.awt.event.ItemListener), ItemEvent, ItemListener


addActionListener

public void addActionListener(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.

Parameters:

l - the action listener

Since:

JDK1.1

See Also:

removeActionListener(java.awt.event.ActionListener), getActionListeners(), ActionEvent, ActionListener


removeActionListener

public void removeActionListener(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.

Parameters:

l - the action listener

Since:

JDK1.1

See Also:

addActionListener(java.awt.event.ActionListener), getActionListeners(), ActionEvent, ActionListener


getActionListeners

public ActionListener[] getActionListeners()

Returns an array of all the action listeners registered on this list.

Returns:

all of this list's ActionListeners or an empty array if no action listeners are currently registered

Since:

1.4

See Also:

addActionListener(java.awt.event.ActionListener), removeActionListener(java.awt.event.ActionListener), ActionEvent, ActionListener


getListeners

public <T extends EventListener> T[] getListeners(Class listenerType)

Returns an array of all the objects currently registered as _Foo_Listeners upon this List._Foo_Listeners are registered using theadd_Foo_Listener method.

You can specify the listenerType argument with a class literal, such as_Foo_Listener.class. For example, you can query aList 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.

Overrides:

[getListeners](../../java/awt/Component.html#getListeners%28java.lang.Class%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Parameters:

listenerType - the type of listeners requested; this parameter should specify an interface that descends fromjava.util.EventListener

Returns:

an array of all objects registered as_Foo_Listeners on this list, or an empty array if no such listeners have been added

Throws:

[ClassCastException](../../java/lang/ClassCastException.html "class in java.lang") - if listenerType doesn't specify a class or interface that implementsjava.util.EventListener

Since:

1.3

See Also:

getItemListeners()


processEvent

protected void processEvent(AWTEvent e)

Processes events on this scrolling list. If an event is an instance of ItemEvent, it invokes theprocessItemEvent 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.

Overrides:

[processEvent](../../java/awt/Component.html#processEvent%28java.awt.AWTEvent%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Parameters:

e - the event

Since:

JDK1.1

See Also:

ActionEvent, ItemEvent, processActionEvent(java.awt.event.ActionEvent), processItemEvent(java.awt.event.ItemEvent)


processItemEvent

protected void processItemEvent(ItemEvent e)

Processes item events occurring on this list by dispatching them to any registeredItemListener objects.

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

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

Parameters:

e - the item event

Since:

JDK1.1

See Also:

ItemEvent, ItemListener, addItemListener(java.awt.event.ItemListener), Component.enableEvents(long)


processActionEvent

protected void processActionEvent(ActionEvent e)

Processes action events occurring on this component by dispatching them to any registeredActionListener objects.

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

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

Parameters:

e - the action event

Since:

JDK1.1

See Also:

ActionEvent, ActionListener, addActionListener(java.awt.event.ActionListener), Component.enableEvents(long)


paramString

protected String paramString()

Returns the parameter string representing the state of this scrolling list. This string is useful for debugging.

Overrides:

[paramString](../../java/awt/Component.html#paramString%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Returns:

the parameter string of this scrolling list


delItems

@Deprecated public void delItems(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.


getAccessibleContext

public AccessibleContext getAccessibleContext()

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.

Specified by:

[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29) in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")

Overrides:

[getAccessibleContext](../../java/awt/Component.html#getAccessibleContext%28%29) in class [Component](../../java/awt/Component.html "class in java.awt")

Returns:

an AccessibleAWTList that serves as the AccessibleContext of this List



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.