| Method from java.awt.List Detail: |
public void add(String item) {
addItem(item);
}
Adds the specified item to the end of scrolling list. |
public void add(String item,
int index) {
addItem(item, 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. |
public synchronized void addActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
newEventsOnly = true;
}
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. |
public void addItem(String item) {
addItem(item, -1);
} Deprecated! replaced - by add(String).
|
public synchronized void addItem(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);
}
} Deprecated! replaced - by add(String, int).
|
public synchronized void addItemListener(ItemListener l) {
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.add(itemListener, l);
newEventsOnly = true;
}
|
public void addNotify() {
synchronized (getTreeLock()) {
if (peer == null)
peer = getToolkit().createList(this);
super.addNotify();
}
}
Creates the peer for the list. The peer allows us to modify the
list's appearance without changing its functionality. |
public boolean allowsMultipleSelections() {
return multipleMode;
} Deprecated! As - of JDK version 1.1,
replaced by isMultipleMode().
|
public synchronized void clear() {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.clear();
}
items = new Vector();
selected = new int[0];
} Deprecated! As - of JDK version 1.1,
replaced by removeAll().
|
String constructComponentName() {
synchronized (List.class) {
return base + nameCounter++;
}
}
Construct a name for this component. Called by
getName when the name is null. |
public int countItems() {
return items.size();
} Deprecated! As - of JDK version 1.1,
replaced by getItemCount().
|
public void delItem(int position) {
delItems(position, position);
} Deprecated! replaced - by remove(String)
and remove(int).
|
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);
}
} 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.
|
public synchronized void deselect(int index) {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
if (isMultipleMode() || (getSelectedIndex() == index)) {
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;
}
}
}
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. |
boolean eventEnabled(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 AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTList();
}
return accessibleContext;
}
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. |
public synchronized ActionListener[] getActionListeners() {
return (ActionListener[])(getListeners(ActionListener.class));
}
Returns an array of all the action listeners
registered on this list. |
public String getItem(int index) {
return getItemImpl(index);
}
Gets the item associated with the specified index. |
public int getItemCount() {
return countItems();
}
Gets the number of items in the list. |
final String getItemImpl(int index) {
return (String)items.elementAt(index);
}
|
public synchronized ItemListener[] getItemListeners() {
return (ItemListener[])(getListeners(ItemListener.class));
}
Returns an array of all the item listeners
registered on this list. |
public synchronized String[] getItems() {
String itemCopies[] = new String[items.size()];
items.copyInto(itemCopies);
return itemCopies;
}
Gets the items in the list. |
public T[] getListeners(Class listenerType) {
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);
}
Returns an array of all the objects currently registered
as FooListeners
upon this List.
FooListeners 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. |
public Dimension getMinimumSize() {
return minimumSize();
}
Determines the minimum size of this scrolling list. |
public Dimension getMinimumSize(int rows) {
return minimumSize(rows);
}
Gets the minumum dimensions for a list with the specified
number of rows. |
public Dimension getPreferredSize() {
return preferredSize();
}
Gets the preferred size of this scrolling list. |
public Dimension getPreferredSize(int rows) {
return preferredSize(rows);
}
Gets the preferred dimensions for a list with the specified
number of rows. |
public int getRows() {
return rows;
}
Gets the number of visible lines in this list. Note that
once the List has been created, this number
will never change. |
public synchronized int getSelectedIndex() {
int sel[] = getSelectedIndexes();
return (sel.length == 1) ? sel[0] : -1;
}
Gets the index of the selected item on the list, |
public synchronized int[] getSelectedIndexes() {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
selected = ((ListPeer)peer).getSelectedIndexes();
}
return (int[])selected.clone();
}
Gets the selected indexes on the list. |
public synchronized String getSelectedItem() {
int index = getSelectedIndex();
return (index < 0) ? null : getItem(index);
}
Gets the selected item on this scrolling list. |
public synchronized String[] getSelectedItems() {
int sel[] = getSelectedIndexes();
String str[] = new String[sel.length];
for (int i = 0 ; i < sel.length ; i++) {
str[i] = getItem(sel[i]);
}
return str;
}
Gets the selected items on this scrolling list. |
public Object[] getSelectedObjects() {
return getSelectedItems();
}
Gets the selected items on this scrolling list in an array of Objects. |
public int getVisibleIndex() {
return visibleIndex;
}
Gets the index of the item that was last made visible by
the method makeVisible. |
public boolean isIndexSelected(int index) {
return isSelected(index);
}
Determines if the specified item in this scrolling list is
selected. |
public boolean isMultipleMode() {
return allowsMultipleSelections();
}
Determines whether this list allows multiple selections. |
public boolean isSelected(int index) {
int sel[] = getSelectedIndexes();
for (int i = 0 ; i < sel.length ; i++) {
if (sel[i] == index) {
return true;
}
}
return false;
} Deprecated! As - of JDK version 1.1,
replaced by isIndexSelected(int).
|
public synchronized void makeVisible(int index) {
visibleIndex = index;
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.makeVisible(index);
}
}
Makes the item at the specified index visible. |
public Dimension minimumSize() {
synchronized (getTreeLock()) {
return (rows > 0) ? minimumSize(rows) : super.minimumSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getMinimumSize().
|
public Dimension minimumSize(int rows) {
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
return (peer != null) ?
peer.minimumSize(rows) :
super.minimumSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getMinimumSize(int).
|
protected String paramString() {
return super.paramString() + ",selected=" + getSelectedItem();
}
Returns the parameter string representing the state of this
scrolling list. This string is useful for debugging. |
public Dimension preferredSize() {
synchronized (getTreeLock()) {
return (rows > 0) ?
preferredSize(rows) :
super.preferredSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getPreferredSize().
|
public Dimension preferredSize(int rows) {
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
return (peer != null) ?
peer.preferredSize(rows) :
super.preferredSize();
}
} Deprecated! As - of JDK version 1.1,
replaced by getPreferredSize(int).
|
protected void processActionEvent(ActionEvent e) {
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(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. |
protected void processEvent(AWTEvent e) {
if (e instanceof ItemEvent) {
processItemEvent((ItemEvent)e);
return;
} else if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
return;
}
super.processEvent(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. |
protected void processItemEvent(ItemEvent e) {
ItemListener listener = itemListener;
if (listener != null) {
listener.itemStateChanged(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. |
public synchronized void remove(String item) {
int index = items.indexOf(item);
if (index < 0) {
throw new IllegalArgumentException("item " + item +
" not found in list");
} else {
remove(index);
}
}
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. |
public void remove(int position) {
delItem(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. |
public synchronized void removeActionListener(ActionListener l) {
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
|
public void removeAll() {
clear();
}
Removes all items from this list. |
public synchronized void removeItemListener(ItemListener l) {
if (l == null) {
return;
}
itemListener = AWTEventMulticaster.remove(itemListener, l);
}
|
public void removeNotify() {
synchronized (getTreeLock()) {
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
selected = peer.getSelectedIndexes();
}
super.removeNotify();
}
}
Removes the peer for this list. The peer allows us to modify the
list's appearance without changing its functionality. |
public synchronized void replaceItem(String newValue,
int index) {
remove(index);
add(newValue, index);
}
Replaces the item at the specified index in the scrolling list
with the new string. |
public void select(int index) {
// 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);
}
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. |
public void setMultipleMode(boolean b) {
setMultipleSelections(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. |
public synchronized void setMultipleSelections(boolean b) {
if (b != multipleMode) {
multipleMode = b;
ListPeer peer = (ListPeer)this.peer;
if (peer != null) {
peer.setMultipleSelections(b);
}
}
} Deprecated! As - of JDK version 1.1,
replaced by setMultipleMode(boolean).
|