java.awt
Class List

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.List
All Implemented Interfaces:
java.awt.image.ImageObserver

public class List
extends Component

A scrolling list of text items.


Field Summary
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
List()
          Creates a new scrolling list initialized with no visible Lines or multiple selections.
List(int rows, boolean multipleSelections)
          Creates a new scrolling list initialized with the specified number of visible lines and a boolean stating whether multiple selections are allowed or not.
 
Method Summary
 void addItem(String item)
          Adds the specified item to the end of scrolling list.
 void addItem(String item, int index)
          Adds the specified item to the end of scrolling list.
 void addNotify()
          Creates the peer for the list.
 boolean allowsMultipleSelections()
          Returns true if this list allows multiple selections.
 void clear()
          Clears the list.
 int countItems()
          Returns the number of items in the list.
 void delItem(int position)
          Delete an item from the list.
 void delItems(int start, int end)
          Delete multiple items from the list.
 void deselect(int index)
          Deselects the item at the specified index.
 String getItem(int index)
          Gets the item associated with the specified index.
 int getRows()
          Returns the number of visible lines in this list.
 int getSelectedIndex()
          Get the selected item on the list or -1 if no item is selected.
 int[] getSelectedIndexes()
          Returns the selected indexes on the list.
 String getSelectedItem()
          Returns the selected item on the list or null if no item is selected.
 String[] getSelectedItems()
          Returns the selected items on the list.
 int getVisibleIndex()
          Gets the index of the item that was last made visible by the method makeVisible.
 boolean isSelected(int index)
          Returns true if the item at the specified index has been selected; false otherwise.
 void makeVisible(int index)
          Forces the item at the specified index to be visible.
 Dimension minimumSize()
          Returns the minimum dimensions needed for the list.
 Dimension minimumSize(int rows)
          Returns the minimum dimensions needed for the amount of rows in the list.
protected  String paramString()
          Returns the parameter String of this list.
 Dimension preferredSize()
          Returns the preferred dimensions needed for the list.
 Dimension preferredSize(int rows)
          Returns the preferred dimensions needed for the list with the specified amount of rows.
 void removeNotify()
          Removes the peer for this list.
 void replaceItem(String newValue, int index)
          Replaces the item at the given index.
 void select(int index)
          Selects the item at the specified index.
 void setMultipleSelections(boolean v)
          Sets whether this list should allow multiple selections or not.
 
Methods inherited from class java.awt.Component
action, bounds, checkImage, checkImage, createImage, createImage, deliverEvent, disable, enable, enable, getBackground, getColorModel, getFont, getFontMetrics, getForeground, getGraphics, getParent, getPeer, getToolkit, gotFocus, handleEvent, hide, imageUpdate, inside, invalidate, isEnabled, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setFont, setForeground, show, show, size, toString, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

List

public List()
Creates a new scrolling list initialized with no visible Lines or multiple selections.


List

public List(int rows,
            boolean multipleSelections)
Creates a new scrolling list initialized with the specified number of visible lines and a boolean stating whether multiple selections are allowed or not.

Parameters:
rows - the number of items to show.
multipleSelections - if true then multiple selections are allowed.
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 in class Component
See Also:
Component.getPeer(), 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 in class Component
See Also:
Component.getPeer(), Component.addNotify()

countItems

public int countItems()
Returns the number of items in the list.

See Also:
getItem(int)

getItem

public String getItem(int index)
Gets the item associated with the specified index.

Parameters:
index - the position of the item
See Also:
countItems()

addItem

public void addItem(String item)
Adds the specified item to the end of scrolling list.

Parameters:
item - the item to be added

addItem

public void addItem(String item,
                    int index)
Adds the specified item to the end of scrolling list.

Parameters:
item - the item to be added
index - the position at which to put in the item. The index is zero-based. If index is -1 then the item is added to the end. If index is greater than the number of items in the list, the item gets added at the end.

replaceItem

public void replaceItem(String newValue,
                        int index)
Replaces the item at the given index.

Parameters:
newValue - the new value to replace the existing item
index - the position of the item to replace

clear

public void clear()
Clears the list.

See Also:
delItem(int), delItems(int, int)

delItem

public void delItem(int position)
Delete an item from the list.


delItems

public void delItems(int start,
                     int end)
Delete multiple items from the list.


getSelectedIndex

public int getSelectedIndex()
Get the selected item on the list or -1 if no item is selected.

See Also:
select(int), deselect(int), isSelected(int)

getSelectedIndexes

public int[] getSelectedIndexes()
Returns the selected indexes on the list.

See Also:
select(int), deselect(int), isSelected(int)

getSelectedItem

public String getSelectedItem()
Returns the selected item on the list or null if no item is selected.

See Also:
select(int), deselect(int), isSelected(int)

getSelectedItems

public String[] getSelectedItems()
Returns the selected items on the list.

See Also:
select(int), deselect(int), isSelected(int)

select

public void select(int index)
Selects the item at the specified index.

Parameters:
index - the position of the item to select
See Also:
getSelectedItem(), deselect(int), isSelected(int)

deselect

public void deselect(int index)
Deselects the item at the specified index.

Parameters:
index - the position of the item to deselect
See Also:
select(int), getSelectedItem(), isSelected(int)

isSelected

public boolean isSelected(int index)
Returns true if the item at the specified index has been selected; false otherwise.

Parameters:
index - the item to be checked
See Also:
select(int), deselect(int), isSelected(int)

getRows

public int getRows()
Returns the number of visible lines in this list.


allowsMultipleSelections

public boolean allowsMultipleSelections()
Returns true if this list allows multiple selections.

See Also:
setMultipleSelections(boolean)

setMultipleSelections

public void setMultipleSelections(boolean v)
Sets whether this list should allow multiple selections or not.

Parameters:
v - the boolean to allow multiple selections
See Also:
allowsMultipleSelections()

getVisibleIndex

public int getVisibleIndex()
Gets the index of the item that was last made visible by the method makeVisible.


makeVisible

public void makeVisible(int index)
Forces the item at the specified index to be visible.

Parameters:
index - the position of the item
See Also:
getVisibleIndex()

preferredSize

public Dimension preferredSize(int rows)
Returns the preferred dimensions needed for the list with the specified amount of rows.

Parameters:
rows - amount of rows in list.

preferredSize

public Dimension preferredSize()
Returns the preferred dimensions needed for the list.

Overrides:
preferredSize in class Component
Returns:
the preferred size with the specified number of rows if the row size is greater than 0.
See Also:
Component.minimumSize(), LayoutManager

minimumSize

public Dimension minimumSize(int rows)
Returns the minimum dimensions needed for the amount of rows in the list.

Parameters:
rows - minimum amount of rows in the list

minimumSize

public Dimension minimumSize()
Returns the minimum dimensions needed for the list.

Overrides:
minimumSize in class Component
Returns:
the preferred size with the specified number of rows if the row size is greater than zero.
See Also:
Component.preferredSize(), LayoutManager

paramString

protected String paramString()
Returns the parameter String of this list.

Overrides:
paramString in class Component