GeezerVison is showing docs.oracle.com — List (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
-
-
Nested Class Summary
Nested Classes
| Modifier and Type |
Class |
Description |
protected class |
List.AccessibleAWTList |
This class implements accessibility support for the
List class.
|
-
Constructor Summary
Constructors
| Constructor |
Description |
List() |
Creates a new scrolling list.
|
List(int rows) |
Creates a new scrolling list initialized with the specified
number of visible lines.
|
List(int rows,
boolean multipleMode) |
Creates a new scrolling list initialized to display the specified
number of rows.
|
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods
| Modifier and Type |
Method |
Description |
void |
add(String item) |
Adds the specified item to the end of scrolling list.
|
void |
add(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(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(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<T> listenerType) |
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(int rows) |
Gets the minimum 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 registered
ActionListener 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 registered
ItemListener 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(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, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, 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, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
-
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 for
List(0, false). Also note that the number of visible
lines in the list cannot be changed after it has been created.
- Throws:
HeadlessException - 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 for
List(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 - 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 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.
- 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 - if GraphicsEnvironment.isHeadless()
returns true.
- See Also:
GraphicsEnvironment.isHeadless()
-
Method Detail
-
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 - if index
is out of range
-
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 - 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 - if the position is less than 0 or
greater than getItemCount()-1
- Since:
- JDK1.1
- See Also:
add(String, int)
-
isSelected
@Deprecated
public boolean isSelected(int index)
Deprecated. As of JDK version 1.1,
replaced by isIndexSelected(int).
-
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).
-
preferredSize
@Deprecated
public Dimension preferredSize(int rows)
Deprecated. As of JDK version 1.1,
replaced by getPreferredSize(int).
-
minimumSize
@Deprecated
public Dimension minimumSize(int rows)
Deprecated. As of JDK version 1.1,
replaced by getMinimumSize(int).
-
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 in interface Accessible
- Overrides:
getAccessibleContext in class Component
- Returns:
- an
AccessibleAWTList that serves as the
AccessibleContext of this List
- Since:
- 1.3
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|