|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.List
, ItemSelectable
, MenuContainer
, Serializable
, Accessible

public class List

, 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:
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.
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 |
| Field Summary |
|---|
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
List
Creates a new scrolling list. |
|
List
Creates a new scrolling list initialized with the specified number of visible lines. |
|
List
Creates a new scrolling list initialized to display the specified number of rows. |
|
| Method Summary | ||
|---|---|---|
void |
add
Adds the specified item to the end of scrolling list. |
|
void |
add
Adds the specified item to the the scrolling list at the position indicated by the index. |
|
void |
addActionListener
Adds the specified action listener to receive action events from this list. |
|
void |
addItem
Deprecated. replaced by add(String). |
|
void |
addItem
Deprecated. replaced by add(String, int). |
|
void |
addItemListener
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
Deprecated. replaced by remove(String)
and remove(int). |
|
void |
delItems
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
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
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. |
|
|
getListeners
Returns an array of all the objects currently registered as FooListeners
upon this List. |
|
Dimension |
getMinimumSize
Determines the minimum size of this scrolling list. |
|
Dimension |
getMinimumSize
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
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
Determines if the specified item in this scrolling list is selected. |
|
boolean |
isMultipleMode
Determines whether this list allows multiple selections. |
|
boolean |
isSelected
Deprecated. As of JDK version 1.1, replaced by isIndexSelected(int). |
|
void |
makeVisible
Makes the item at the specified index visible. |
|
Dimension |
minimumSize
Deprecated. As of JDK version 1.1, replaced by getMinimumSize(). |
|
Dimension |
minimumSize
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
Deprecated. As of JDK version 1.1, replaced by getPreferredSize(int). |
|
protected void |
processActionEvent
Processes action events occurring on this component by dispatching them to any registered ActionListener objects. |
|
protected void |
processEvent
Processes events on this scrolling list. |
|
protected void |
processItemEvent
Processes item events occurring on this list by dispatching them to any registered ItemListener objects. |
|
void |
remove
Removes the item at the specified position from this scrolling list. |
|
void |
remove
Removes the first occurrence of an item from the list. |
|
void |
removeActionListener
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
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
Replaces the item at the specified index in the scrolling list with the new string. |
|
void |
select
Selects the item at the specified index in the scrolling list. |
|
void |
setMultipleMode
Sets the flag that determines whether this list allows multiple selections. |
|
void |
setMultipleSelections
Deprecated. As of JDK version 1.1, replaced by setMultipleMode(boolean). |
|
Methods inherited from class java.awt.Component ![]() |
|---|
action |