Methods Summary |
---|
public void | add(java.lang.String item)Adds the specified item to the end of scrolling list.
addItem(item);
|
public void | add(java.lang.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.
addItem(item, index);
|
public synchronized void | addActionListener(java.awt.event.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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
newEventsOnly = true;
|
public void | addItem(java.lang.String item)
addItem(item, -1);
|
public synchronized void | addItem(java.lang.String item, int index)
if (index < -1 || index >= items.size()) {
index = -1;
}
if (item == null) {
item = "";
}
if (index == -1) {
items.addElement(item);
} else {
items.insertElementAt(item, index);
}
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.addItem(item, index);
}
|
public synchronized void | addItemListener(java.awt.event.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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.add(itemListener, l);
newEventsOnly = true;
|
public void | addNotify()Creates the peer for the list. The peer allows us to modify the
list's appearance without changing its functionality.
synchronized (getTreeLock()) {
if (peer == null)
peer = getToolkit().createList(this);
super.addNotify();
}
|
public boolean | allowsMultipleSelections()
return multipleMode;
|
public synchronized void | clear()
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.clear();
}
items = new Vector();
selected = new int[0];
|
java.lang.String | constructComponentName()Construct a name for this component. Called by
getName when the name is null .
synchronized (getClass()) {
return base + nameCounter++;
}
|
public int | countItems()
return items.size();
|
public void | delItem(int position)
delItems(position, position);
|
public synchronized void | delItems(int start, int end)
for (int i = end; i >= start; i--) {
items.removeElementAt(i);
}
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.delItems(start, end);
}
|
public synchronized 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.
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.deselect(index);
}
for (int i = 0 ; i < selected.length ; i++) {
if (selected[i] == index) {
int newsel[] = new int[selected.length - 1];
System.arraycopy(selected, 0, newsel, 0, i);
System.arraycopy(selected, i+1, newsel, i, selected.length - (i+1));
selected = newsel;
return;
}
}
|
boolean | eventEnabled(java.awt.AWTEvent e)
switch(e.id) {
case ActionEvent.ACTION_PERFORMED:
if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
actionListener != null) {
return true;
}
return false;
case ItemEvent.ITEM_STATE_CHANGED:
if ((eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 ||
itemListener != null) {
return true;
}
return false;
default:
break;
}
return super.eventEnabled(e);
|
public javax.accessibility.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.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTList();
}
return accessibleContext;
|
public synchronized java.awt.event.ActionListener[] | getActionListeners()Returns an array of all the action listeners
registered on this list.
return (ActionListener[])(getListeners(ActionListener.class));
|
public java.lang.String | getItem(int index)Gets the item associated with the specified index.
return getItemImpl(index);
|
public int | getItemCount()Gets the number of items in the list.
return countItems();
|
final java.lang.String | getItemImpl(int index)
return (String)items.elementAt(index);
|
public synchronized java.awt.event.ItemListener[] | getItemListeners()Returns an array of all the item listeners
registered on this list.
return (ItemListener[])(getListeners(ItemListener.class));
|
public synchronized java.lang.String[] | getItems()Gets the items in the list.
String itemCopies[] = new String[items.size()];
items.copyInto(itemCopies);
return itemCopies;
|
public T[] | getListeners(java.lang.Class listenerType)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.
EventListener l = null;
if (listenerType == ActionListener.class) {
l = actionListener;
} else if (listenerType == ItemListener.class) {
l = itemListener;
} else {
return super.getListeners(listenerType);
}
return AWTEventMulticaster.getListeners(l, listenerType);
|
public java.awt.Dimension | getMinimumSize(int rows)Gets the minumum dimensions for a list with the specified
number of rows.
return minimumSize(rows);
|
public java.awt.Dimension | getMinimumSize()Determines the minimum size of this scrolling list.
return minimumSize();
|
public java.awt.Dimension | getPreferredSize(int rows)Gets the preferred dimensions for a list with the specified
number of rows.
return preferredSize(rows);
|
public java.awt.Dimension | getPreferredSize()Gets the preferred size of this scrolling list.
return preferredSize();
|
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.
return rows;
|
public synchronized int | getSelectedIndex()Gets the index of the selected item on the list,
int sel[] = getSelectedIndexes();
return (sel.length == 1) ? sel[0] : -1;
|
public synchronized int[] | getSelectedIndexes()Gets the selected indexes on the list.
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
selected = ((ListPeer)peer).getSelectedIndexes();
}
return (int[])selected.clone();
|
public synchronized java.lang.String | getSelectedItem()Gets the selected item on this scrolling list.
int index = getSelectedIndex();
return (index < 0) ? null : getItem(index);
|
public synchronized java.lang.String[] | getSelectedItems()Gets the selected items on this scrolling list.
int sel[] = getSelectedIndexes();
String str[] = new String[sel.length];
for (int i = 0 ; i < sel.length ; i++) {
str[i] = getItem(sel[i]);
}
return str;
|
public java.lang.Object[] | getSelectedObjects()Gets the selected items on this scrolling list in an array of Objects.
return getSelectedItems();
|
public int | getVisibleIndex()Gets the index of the item that was last made visible by
the method makeVisible .
return visibleIndex;
|
public boolean | isIndexSelected(int index)Determines if the specified item in this scrolling list is
selected.
return isSelected(index);
|
public boolean | isMultipleMode()Determines whether this list allows multiple selections.
return allowsMultipleSelections();
|
public boolean | isSelected(int index)
int sel[] = getSelectedIndexes();
for (int i = 0 ; i < sel.length ; i++) {
if (sel[i] == index) {
return true;
}
}
return false;
|
public synchronized void | makeVisible(int index)Makes the item at the specified index visible.
visibleIndex = index;
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.makeVisible(index);
}
|
public java.awt.Dimension | minimumSize(int rows)
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
return (peer != null) ?
peer.minimumSize(rows) :
super.minimumSize();
}
|
public java.awt.Dimension | minimumSize()
synchronized (getTreeLock()) {
return (rows > 0) ? minimumSize(rows) : super.minimumSize();
}
|
protected java.lang.String | paramString()Returns the parameter string representing the state of this
scrolling list. This string is useful for debugging.
return super.paramString() + ",selected=" + getSelectedItem();
|
public java.awt.Dimension | preferredSize(int rows)
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
return (peer != null) ?
peer.preferredSize(rows) :
super.preferredSize();
}
|
public java.awt.Dimension | preferredSize()
synchronized (getTreeLock()) {
return (rows > 0) ?
preferredSize(rows) :
super.preferredSize();
}
|
protected void | processActionEvent(java.awt.event.ActionEvent e)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:
- An
ActionListener object is registered
via addActionListener .
- Action events are enabled via
enableEvents .
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
|
protected void | processEvent(java.awt.AWTEvent e)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.
if (e instanceof ItemEvent) {
processItemEvent((ItemEvent)e);
return;
} else if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
return;
}
super.processEvent(e);
|
protected void | processItemEvent(java.awt.event.ItemEvent e)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:
- An
ItemListener object is registered
via addItemListener .
- Item events are enabled via
enableEvents .
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
ItemListener listener = itemListener;
if (listener != null) {
listener.itemStateChanged(e);
}
|
private void | readObject(java.io.ObjectInputStream s)Reads the ObjectInputStream and if it
isn't null adds a listener to receive
both item events and action events (as specified
by the key stored in the stream) fired by the
List .
Unrecognized keys or values will be ignored.
GraphicsEnvironment.checkHeadless();
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (itemListenerK == key)
addItemListener((ItemListener)(s.readObject()));
else if (actionListenerK == key)
addActionListener((ActionListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
|
public synchronized void | remove(java.lang.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.
int index = items.indexOf(item);
if (index < 0) {
throw new IllegalArgumentException("item " + item +
" not found in list");
} else {
remove(index);
}
|
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.
delItem(position);
|
public synchronized void | removeActionListener(java.awt.event.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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
|
public void | removeAll()Removes all items from this list.
clear();
|
public synchronized void | removeItemListener(java.awt.event.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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.remove(itemListener, l);
|
public void | removeNotify()Removes the peer for this list. The peer allows us to modify the
list's appearance without changing its functionality.
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
selected = peer.getSelectedIndexes();
}
super.removeNotify();
}
|
public synchronized void | replaceItem(java.lang.String newValue, int index)Replaces the item at the specified index in the scrolling list
with the new string.
remove(index);
add(newValue, index);
|
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 an
ItemEvent is by user interaction.
// Bug #4059614: select can't be synchronized while calling the peer,
// because it is called from the Window Thread. It is sufficient to
// synchronize the code that manipulates 'selected' except for the
// case where the peer changes. To handle this case, we simply
// repeat the selection process.
ListPeer peer;
do {
peer = (ListPeer)this.peer;
if (peer != null) {
peer.select(index);
return;
}
synchronized(this)
{
boolean alreadySelected = false;
for (int i = 0 ; i < selected.length ; i++) {
if (selected[i] == index) {
alreadySelected = true;
break;
}
}
if (!alreadySelected) {
if (!multipleMode) {
selected = new int[1];
selected[0] = index;
} else {
int newsel[] = new int[selected.length + 1];
System.arraycopy(selected, 0, newsel, 0,
selected.length);
newsel[selected.length] = index;
selected = newsel;
}
}
}
} while (peer != this.peer);
|
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.
setMultipleSelections(b);
|
public synchronized void | setMultipleSelections(boolean b)
if (b != multipleMode) {
multipleMode = b;
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.setMultipleSelections(b);
}
}
|
private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to stream. Writes
a list of serializable ItemListeners
and ActionListeners as optional data.
The non-serializable listeners are detected and
no attempt is made to serialize them.
synchronized (this) {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
selected = peer.getSelectedIndexes();
}
}
s.defaultWriteObject();
AWTEventMulticaster.save(s, itemListenerK, itemListener);
AWTEventMulticaster.save(s, actionListenerK, actionListener);
s.writeObject(null);
|