java.lang.Object | ||
↳ | java.awt.Component | |
↳ | java.awt.List |
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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
List.AccessibleAWTList | This class implements accessibility support for the
List class. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.awt.Component
| |||||||||||
From interface
java.awt.image.ImageObserver
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new scrolling list.
| |||||||||||
Creates a new scrolling list initialized with the specified
number of visible lines.
| |||||||||||
Creates a new scrolling list initialized to display the specified
number of rows.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds the specified item to the the scrolling list
at the position indicated by the index.
| |||||||||||
Adds the specified item to the end of scrolling list.
| |||||||||||
Adds the specified action listener to receive action events from
this list.
| |||||||||||
This method is deprecated.
replaced by
add(String) .
| |||||||||||
This method is deprecated.
replaced by
add(String, int) .
| |||||||||||
Adds the specified item listener to receive item events from
this list.
| |||||||||||
Creates the peer for the list.
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
isMultipleMode() .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
removeAll() .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
getItemCount() .
| |||||||||||
This method is deprecated.
replaced by
remove(String)
and remove(int) .
| |||||||||||
This method is 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.
| |||||||||||
Deselects the item at the specified index.
| |||||||||||
Gets the
AccessibleContext associated with this
List . | |||||||||||
Returns an array of all the action listeners
registered on this list.
| |||||||||||
Gets the item associated with the specified index.
| |||||||||||
Gets the number of items in the list.
| |||||||||||
Returns an array of all the item listeners
registered on this list.
| |||||||||||
Gets the items in the list.
| |||||||||||
Returns an array of all the objects currently registered
as
FooListener s
upon this List . | |||||||||||
Determines the minimum size of this scrolling list.
| |||||||||||
Gets the minumum dimensions for a list with the specified
number of rows.
| |||||||||||
Gets the preferred size of this scrolling list.
| |||||||||||
Gets the preferred dimensions for a list with the specified
number of rows.
| |||||||||||
Gets the number of visible lines in this list.
| |||||||||||
Gets the index of the selected item on the list,
| |||||||||||
Gets the selected indexes on the list.
| |||||||||||
Gets the selected item on this scrolling list.
| |||||||||||
Gets the selected items on this scrolling list.
| |||||||||||
Gets the selected items on this scrolling list in an array of Objects.
| |||||||||||
Gets the index of the item that was last made visible by
the method
makeVisible . | |||||||||||
Determines if the specified item in this scrolling list is
selected.
| |||||||||||
Determines whether this list allows multiple selections.
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
isIndexSelected(int) .
| |||||||||||
Makes the item at the specified index visible.
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
getMinimumSize(int) .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
getMinimumSize() .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
getPreferredSize(int) .
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
getPreferredSize() .
| |||||||||||
Removes the first occurrence of an item from the list.
| |||||||||||
Removes the item at the specified position
from this scrolling list.
| |||||||||||
Removes the specified action listener so that it no longer
receives action events from this list.
| |||||||||||
Removes all items from this list.
| |||||||||||
Removes the specified item listener so that it no longer
receives item events from this list.
| |||||||||||
Removes the peer for this list.
| |||||||||||
Replaces the item at the specified index in the scrolling list
with the new string.
| |||||||||||
Selects the item at the specified index in the scrolling list.
| |||||||||||
Sets the flag that determines whether this list
allows multiple selections.
| |||||||||||
This method is deprecated.
As of JDK version 1.1,
replaced by
setMultipleMode(boolean) .
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the parameter string representing the state of this
scrolling list.
| |||||||||||
Processes action events occurring on this component
by dispatching them to any registered
ActionListener objects. | |||||||||||
Processes events on this scrolling list.
| |||||||||||
Processes item events occurring on this list by
dispatching them to any registered
ItemListener objects. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.awt.Component
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.awt.ItemSelectable
| |||||||||||
From interface
java.awt.MenuContainer
| |||||||||||
From interface
java.awt.image.ImageObserver
| |||||||||||
From interface
javax.accessibility.Accessible
|
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.
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
rows | the number of items to show. |
---|
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
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. |
HeadlessException | if GraphicsEnvironment.isHeadless() returns true. |
---|
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.
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 |
Adds the specified item to the end of scrolling list.
item | the item to be added |
---|
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.
l | the action listener |
---|
This method is deprecated.
replaced by add(String, int)
.
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.
l | the item listener |
---|
Creates the peer for the list. The peer allows us to modify the list's appearance without changing its functionality.
This method is deprecated.
As of JDK version 1.1,
replaced by isMultipleMode()
.
This method is deprecated.
As of JDK version 1.1,
replaced by removeAll()
.
This method is deprecated.
As of JDK version 1.1,
replaced by getItemCount()
.
This method is deprecated.
replaced by remove(String)
and remove(int)
.
This method is 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.
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.
index | the position of the item to deselect |
---|
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.
AccessibleAWTList
that serves as the
AccessibleContext
of this List
Returns an array of all the action listeners registered on this list.
ActionListener
s
or an empty array if no action
listeners are currently registeredGets the item associated with the specified index.
index | the position of the item |
---|
Returns an array of all the item listeners registered on this list.
ItemListener
s
or an empty array if no item
listeners are currently registeredGets the items in the list.
Returns an array of all the objects currently registered
as FooListener
s
upon this List
.
FooListener
s 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.
listenerType | the type of listeners requested; this parameter
should specify an interface that descends from
java.util.EventListener |
---|
FooListener
s on this list,
or an empty array if no such
listeners have been addedClassCastException | if listenerType
doesn't specify a class or interface that implements
java.util.EventListener |
---|
Determines the minimum size of this scrolling list.
Gets the minumum dimensions for a list with the specified number of rows.
rows | number of rows in the list |
---|
Gets the preferred size of this scrolling list.
Gets the preferred dimensions for a list with the specified number of rows.
rows | number of rows in the list |
---|
Gets the number of visible lines in this list. Note that
once the List
has been created, this number
will never change.
Gets the index of the selected item on the list,
-1
is returned.Gets the selected indexes on the list.
Gets the selected item on this scrolling list.
null
is returned.Gets the selected items on this scrolling list.
Gets the selected items on this scrolling list in an array of Objects.
Object
s representing the
selected items on this scrolling list;
if no item is selected, a zero-length array is returned.Gets the index of the item that was last made visible by
the method makeVisible
.
Determines if the specified item in this scrolling list is selected.
index | the item to be checked |
---|
true
if the specified item has been
selected; false
otherwiseDetermines whether this list allows multiple selections.
true
if this list allows multiple
selections; otherwise, false
This method is deprecated.
As of JDK version 1.1,
replaced by isIndexSelected(int)
.
Makes the item at the specified index visible.
index | the position of the item |
---|
This method is deprecated.
As of JDK version 1.1,
replaced by getMinimumSize(int)
.
This method is deprecated.
As of JDK version 1.1,
replaced by getMinimumSize()
.
This method is deprecated.
As of JDK version 1.1,
replaced by getPreferredSize(int)
.
This method is deprecated.
As of JDK version 1.1,
replaced by getPreferredSize()
.
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.
item | the item to remove from the list |
---|
IllegalArgumentException | if the item doesn't exist in the list |
---|
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.
position | the index of the item to delete |
---|
ArrayIndexOutOfBoundsException | if the position is less than 0 or
greater than getItemCount()-1
|
---|
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.
l | the action listener |
---|
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.
l | the item listener |
---|
Removes the peer for this list. The peer allows us to modify the list's appearance without changing its functionality.
Replaces the item at the specified index in the scrolling list with the new string.
newValue | a new string to replace an existing item |
---|---|
index | the position of the item to replace |
ArrayIndexOutOfBoundsException | if index
is out of range
|
---|
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.
index | the position of the item to select |
---|
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.
b | if true then multiple selections
are allowed; otherwise, only one item from
the list can be selected at once |
---|
This method is deprecated.
As of JDK version 1.1,
replaced by setMultipleMode(boolean)
.
Returns the parameter string representing the state of this scrolling list. This string is useful for debugging.
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:
ActionListener
object is registered
via addActionListener
.
enableEvents
.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e | the action event |
---|
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.
e | the event |
---|
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:
ItemListener
object is registered
via addItemListener
.
enableEvents
.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
e | the item event |
---|