List

Instances of this class represent a selectable user interface object that displays a list of strings and issues notification when a string is selected. A list may be single or multi select. <p> <dl> <dt><b>Styles:</b></dt> <dd>SINGLE, MULTI</dd> <dt><b>Events:</b></dt> <dd>Selection, DefaultSelection</dd> </dl> <p> Note: Only one of SINGLE and MULTI may be specified. </p><p> IMPORTANT: This class is <em>not</em> intended to be subclassed. </p>

@see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a> @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

Constructors

this
this(Composite parent, int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. <p> The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses. </p>

Members

Functions

add
void add(String string)

Adds the argument to the end of the receiver's list.

add
void add(String string, int index)

Adds the argument to the receiver's list at the given zero-relative index. <p> Note: To add an item at the end of the list, use the result of calling <code>getItemCount()</code> as the index or use <code>add(String)</code>. </p>

addSelectionListener
void addSelectionListener(SelectionListener listener)

Adds the listener to the collection of listeners who will be notified when the user changes the receiver's selection, by sending it one of the messages defined in the <code>SelectionListener</code> interface. <p> <code>widgetSelected</code> is called when the selection changes. <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. </p>

deselect
void deselect(int index)

Deselects the item at the given zero-relative index in the receiver. If the item at the index was already deselected, it remains deselected. Indices that are out of range are ignored.

deselect
void deselect(int start, int end)

Deselects the items at the given zero-relative indices in the receiver. If the item at the given zero-relative index in the receiver is selected, it is deselected. If the item at the index was not selected, it remains deselected. The range of the indices is inclusive. Indices that are out of range are ignored.

deselect
void deselect(int[] indices)

Deselects the items at the given zero-relative indices in the receiver. If the item at the given zero-relative index in the receiver is selected, it is deselected. If the item at the index was not selected, it remains deselected. Indices that are out of range and duplicate indices are ignored.

deselectAll
void deselectAll()

Deselects all selected items in the receiver.

getFocusIndex
int getFocusIndex()

Returns the zero-relative index of the item which currently has the focus in the receiver, or -1 if no item has focus.

getItem
String getItem(int index)

Returns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.

getItemCount
int getItemCount()

Returns the number of items contained in the receiver.

getItemHeight
int getItemHeight()

Returns the height of the area which would be used to display <em>one</em> of the items in the list.

getItems
String[] getItems()

Returns a (possibly empty) array of <code>String</code>s which are the items in the receiver. <p> Note: This is not the actual structure used by the receiver to maintain its list of items, so modifying the array will not affect the receiver. </p>

getSelection
String[] getSelection()

Returns an array of <code>String</code>s that are currently selected in the receiver. The order of the items is unspecified. An empty array indicates that no items are selected. <p> Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver. </p> @return an array representing the selection

getSelectionCount
int getSelectionCount()

Returns the number of selected items contained in the receiver.

getSelectionIndex
int getSelectionIndex()

Returns the zero-relative index of the item which is currently selected in the receiver, or -1 if no item is selected.

getSelectionIndices
int[] getSelectionIndices()

Returns the zero-relative indices of the items which are currently selected in the receiver. The order of the indices is unspecified. The array is empty if no items are selected. <p> Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver. </p> @return the array of indices of the selected items

getTopIndex
int getTopIndex()

Returns the zero-relative index of the item which is currently at the top of the receiver. This index can change when items are scrolled or new items are added or removed.

indexOf
int indexOf(String string)

Gets the index of an item. <p> The list is searched starting at 0 until an item is found that is equal to the search item. If no item is found, -1 is returned. Indexing is zero based.

indexOf
int indexOf(String string, int start)

Searches the receiver's list starting at the given, zero-relative index until an item is found that is equal to the argument, and returns the index of that item. If no item is found or the starting index is out of range, returns -1.

isSelected
bool isSelected(int index)

Returns <code>true</code> if the item is selected, and <code>false</code> otherwise. Indices out of range are ignored.

remove
void remove(int index)

Removes the item from the receiver at the given zero-relative index.

remove
void remove(int start, int end)

Removes the items from the receiver which are between the given zero-relative start and end indices (inclusive).

remove
void remove(String string)

Searches the receiver's list starting at the first item until an item is found that is equal to the argument, and removes that item from the list.

remove
void remove(int[] indices)

Removes the items from the receiver at the given zero-relative indices.

removeAll
void removeAll()

Removes all of the items from the receiver. <p> @exception SWTException <ul> <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> </ul>

removeSelectionListener
void removeSelectionListener(SelectionListener listener)

Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.

select
void select(int index)

Selects the item at the given zero-relative index in the receiver's list. If the item at the index was already selected, it remains selected. Indices that are out of range are ignored.

select
void select(int start, int end)

Selects the items in the range specified by the given zero-relative indices in the receiver. The range of indices is inclusive. The current selection is not cleared before the new items are selected. <p> If an item in the given range is not selected, it is selected. If an item in the given range was already selected, it remains selected. Indices that are out of range are ignored and no items will be selected if start is greater than end. If the receiver is single-select and there is more than one item in the given range, then all indices are ignored.

select
void select(int[] indices)

Selects the items at the given zero-relative indices in the receiver. The current selection is not cleared before the new items are selected. <p> If the item at a given index is not selected, it is selected. If the item at a given index was already selected, it remains selected. Indices that are out of range and duplicate indices are ignored. If the receiver is single-select and multiple indices are specified, then all indices are ignored.

selectAll
void selectAll()

Selects all of the items in the receiver. <p> If the receiver is single-select, do nothing.

setItem
void setItem(int index, String string)

Sets the text of the item in the receiver's list at the given zero-relative index to the string argument.

setItems
void setItems(String[] items)

Sets the receiver's items to be the given array of items.

setSelection
void setSelection(int index)

Selects the item at the given zero-relative index in the receiver. If the item at the index was already selected, it remains selected. The current selection is first cleared, then the new item is selected. Indices that are out of range are ignored.

setSelection
void setSelection(int start, int end)

Selects the items in the range specified by the given zero-relative indices in the receiver. The range of indices is inclusive. The current selection is cleared before the new items are selected. <p> Indices that are out of range are ignored and no items will be selected if start is greater than end. If the receiver is single-select and there is more than one item in the given range, then all indices are ignored.

setSelection
void setSelection(int[] indices)

Selects the items at the given zero-relative indices in the receiver. The current selection is cleared before the new items are selected. <p> Indices that are out of range and duplicate indices are ignored. If the receiver is single-select and multiple indices are specified, then all indices are ignored.

setSelection
void setSelection(String[] items)

Sets the receiver's selection to be the given array of items. The current selection is cleared before the new items are selected. <p> Items that are not in the receiver are ignored. If the receiver is single-select and multiple items are specified, then all items are ignored.

setTopIndex
void setTopIndex(int index)

Sets the zero-relative index of the item which is currently at the top of the receiver. This index can change when items are scrolled or new items are added and removed.

showSelection
void showSelection()

Shows the selection. If the selection is already showing in the receiver, this method simply returns. Otherwise, the items are scrolled until the selection is visible.

Inherited Members

From Scrollable

computeTrim
Rectangle computeTrim(int x, int y, int width, int height)

Given a desired <em>client area</em> for the receiver (as described by the arguments), returns the bounding rectangle which would be required to produce that client area. <p> In other words, it returns a rectangle such that, if the receiver's bounds were set to that rectangle, the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings") would be the rectangle described by the arguments (relative to the receiver's parent). </p>

getClientArea
Rectangle getClientArea()

Returns a rectangle which describes the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings").

getHorizontalBar
ScrollBar getHorizontalBar()

Returns the receiver's horizontal scroll bar if it has one, and null if it does not.

getVerticalBar
ScrollBar getVerticalBar()

Returns the receiver's vertical scroll bar if it has one, and null if it does not.

Meta