public class List extends Scrollable
Note: Only one of SINGLE and MULTI may be specified.
IMPORTANT: This class is not intended to be subclassed.
Constructor and Description |
---|
List(Composite parent,
int style)
Constructs a new instance of this class given its parent
and a style value describing its behavior and appearance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String string)
Adds the argument to the end of the receiver's list.
|
void |
add(java.lang.String string,
int index)
Adds the argument to the receiver's list at the given
zero-relative index.
|
void |
addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners who will
be notified when the receiver's selection changes, by sending
it one of the messages defined in the
SelectionListener
interface. |
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver.
|
void |
deselect(int index)
Deselects the item at the given zero-relative index in the receiver.
|
void |
deselect(int[] indices)
Deselects the items at the given zero-relative indices in the receiver.
|
void |
deselect(int start,
int end)
Deselects the items at the given zero-relative indices in the receiver.
|
void |
deselectAll()
Deselects all selected items in the receiver.
|
<T> T |
getAdapter(java.lang.Class<T> adapter)
Implementation of the
Adaptable interface. |
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.
|
java.lang.String |
getItem(int index)
Returns the item at the given, zero-relative index in the
receiver.
|
int |
getItemCount()
Returns the number of items contained in the receiver.
|
int |
getItemHeight()
Returns the height of the area which would be used to
display one of the items in the list.
|
java.lang.String[] |
getItems()
Returns a (possibly empty) array of
String s which
are the items in the receiver. |
java.lang.String[] |
getSelection()
Returns an array of
String s that are currently
selected in the receiver. |
int |
getSelectionCount()
Returns the number of selected items contained in the receiver.
|
int |
getSelectionIndex()
Returns the zero-relative index of the item which is currently
selected in the receiver, or -1 if no item is selected.
|
int[] |
getSelectionIndices()
Returns the zero-relative indices of the items which are currently
selected in the receiver.
|
int |
getTopIndex()
Returns the zero-relative index of the item which is currently
at the top of the receiver.
|
int |
indexOf(java.lang.String string)
Gets the index of an item.
|
int |
indexOf(java.lang.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.
|
boolean |
isSelected(int index)
Returns
true if the item is selected,
and false otherwise. |
void |
remove(int index)
Removes the item from the receiver at the given
zero-relative index.
|
void |
remove(int[] indices)
Removes the items from the receiver at the given
zero-relative indices.
|
void |
remove(int start,
int end)
Removes the items from the receiver which are
between the given zero-relative start and end
indices (inclusive).
|
void |
remove(java.lang.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.
|
void |
removeAll()
Removes all of the items from the receiver.
|
void |
removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners who will
be notified when the receiver's selection changes.
|
void |
select(int index)
Selects the item at the given zero-relative index in the receiver's
list.
|
void |
select(int[] indices)
Selects the items at the given zero-relative indices in the receiver.
|
void |
select(int start,
int end)
Selects the items in the range specified by the given zero-relative
indices in the receiver.
|
void |
selectAll()
Selects all of the items in the receiver.
|
void |
setData(java.lang.String key,
java.lang.Object value)
Sets the application defined property of the receiver
with the specified name to the given value.
|
void |
setFont(Font font)
Sets the font that the receiver will use to paint textual information
to the font specified by the argument, or to the default font for that
kind of control if the argument is null.
|
void |
setItem(int index,
java.lang.String string)
Sets the text of the item in the receiver's list at the given
zero-relative index to the string argument.
|
void |
setItems(java.lang.String[] items)
Sets the receiver's items to be the given array of items.
|
void |
setSelection(int selection)
Selects the item at the given zero-relative index in the receiver.
|
void |
setSelection(int[] selection)
Selects the items at the given zero-relative indices in the receiver.
|
void |
setSelection(int start,
int end)
Selects the items in the range specified by the given zero-relative
indices in the receiver.
|
void |
setSelection(java.lang.String[] selection)
Sets the receiver's selection to be the given array of items.
|
void |
setTopIndex(int topIndex)
Sets the zero-relative index of the item which is currently
at the top of the receiver.
|
void |
showSelection()
Shows the selection.
|
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCursor, setEnabled, setFocus, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
public List(Composite parent, int style)
The style value is either one of the style constants defined in
class SWT
which is applicable to instances of this
class, or must be built by bitwise OR'ing together
(that is, using the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to constructjava.lang.IllegalArgumentException
- SWTException
- SWT.SINGLE
,
SWT.MULTI
,
Widget.checkSubclass()
,
Widget.getStyle()
public <T> T getAdapter(java.lang.Class<T> adapter)
Widget
Adaptable
interface.
IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
getAdapter
in interface Adaptable
getAdapter
in class Control
adapter
- the lookup classnull
if
there is no adapter associated with the given class.public java.lang.String[] getSelection()
String
s that are currently
selected in the receiver. The order of the items is unspecified.
An empty array indicates that no items are selected.
Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.
SWTException
- public int getSelectionIndex()
SWTException
- public int[] getSelectionIndices()
Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.
SWTException
- public int getSelectionCount()
SWTException
- public void setSelection(int selection)
selection
- the index of the item to selectSWTException
- deselectAll()
,
select(int)
public void setSelection(int[] selection)
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.
selection
- the indices of the items to selectjava.lang.IllegalArgumentException
- SWTException
- deselectAll()
,
select(int[])
public void setSelection(int start, int end)
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.
start
- the start index of the items to selectend
- the end index of the items to selectSWTException
- deselectAll()
,
select(int,int)
public void setSelection(java.lang.String[] selection)
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.
selection
- the array of itemsjava.lang.IllegalArgumentException
- SWTException
- deselectAll()
,
select(int[])
,
setSelection(int[])
public void select(int index)
index
- the index of the item to selectSWTException
- public void select(int[] indices)
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.
indices
- the array of indices for the items to selectjava.lang.IllegalArgumentException
- SWTException
- setSelection(int[])
public void select(int start, int end)
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.
start
- the start of the rangeend
- the end of the rangeSWTException
- setSelection(int,int)
public void selectAll()
If the receiver is single-select, do nothing.
SWTException
- public void deselectAll()
SWTException
- public void deselect(int index)
index
- the index of the item to deselectSWTException
- public void deselect(int start, int end)
start
- the start index of the items to deselectend
- the end index of the items to deselectSWTException
- public void deselect(int[] indices)
indices
- the array of indices for the items to deselectjava.lang.IllegalArgumentException
- SWTException
- public boolean isSelected(int index)
true
if the item is selected,
and false
otherwise. Indices out of
range are ignored.index
- the index of the itemSWTException
- public void setTopIndex(int topIndex)
topIndex
- the index of the top itemSWTException
- public int getTopIndex()
SWTException
- public void showSelection()
SWTException
- public int getFocusIndex()
SWTException
- public void add(java.lang.String string)
string
- the new itemjava.lang.IllegalArgumentException
- SWTException
- add(String,int)
public void add(java.lang.String string, int index)
Note: To add an item at the end of the list, use the
result of calling getItemCount()
as the
index or use add(String)
.
string
- the new itemindex
- the index for the itemjava.lang.IllegalArgumentException
- SWTException
- add(String)
public void remove(int index)
index
- the index for the itemjava.lang.IllegalArgumentException
- SWTException
- public void remove(int start, int end)
start
- the start of the rangeend
- the end of the rangejava.lang.IllegalArgumentException
- SWTException
- public void remove(int[] indices)
indices
- the array of indices of the itemsjava.lang.IllegalArgumentException
- SWTException
- public void remove(java.lang.String string)
string
- the item to removejava.lang.IllegalArgumentException
- SWTException
- public void removeAll()
SWTException
- public void setItem(int index, java.lang.String string)
remove
'ing the old item at the index, and then
add
'ing the new item at that index.index
- the index for the itemstring
- the new text for the itemjava.lang.IllegalArgumentException
- SWTException
- public void setItems(java.lang.String[] items)
items
- the array of itemsjava.lang.IllegalArgumentException
- SWTException
- public java.lang.String getItem(int index)
index
- the index of the item to returnjava.lang.IllegalArgumentException
- SWTException
- public int getItemCount()
SWTException
- public java.lang.String[] getItems()
String
s which
are the items in the receiver.
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.
SWTException
- public int indexOf(java.lang.String string)
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.
string
- the search itemjava.lang.IllegalArgumentException
- SWTException
- public int indexOf(java.lang.String string, int start)
string
- the search itemstart
- the zero-relative index at which to start the searchjava.lang.IllegalArgumentException
- SWTException
- public int getItemHeight()
SWTException
- public void addSelectionListener(SelectionListener listener)
SelectionListener
interface.
widgetSelected
is called when the selection changes.
widgetDefaultSelected
is typically called when an item is double-clicked.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,
SelectionEvent
public void removeSelectionListener(SelectionListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- SelectionListener
,
addSelectionListener(org.eclipse.swt.events.SelectionListener)
public void setFont(Font font)
Control
public void setData(java.lang.String key, java.lang.Object value)
Widget
Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
setData
in class Control
key
- the name of the propertyvalue
- the new value for the propertyWidget.getData(String)
public Point computeSize(int wHint, int hHint, boolean changed)
Control
The preferred size of a control is the size that it would
best be displayed at. The width hint and height hint arguments
allow the caller to ask a control questions such as "Given a particular
width, how high does the control need to be to show all of the contents?"
To indicate that the caller does not wish to constrain a particular
dimension, the constant SWT.DEFAULT
is passed for the hint.
If the changed flag is true
, it indicates that the receiver's
contents have changed, therefore any caches that a layout manager
containing the control may have been keeping need to be flushed. When the
control is resized, the changed flag will be false
, so layout
manager caches can be retained.
computeSize
in class Control
wHint
- the width hint (can be SWT.DEFAULT
)hHint
- the height hint (can be SWT.DEFAULT
)changed
- true
if the control's contents have changed, and false
otherwiseLayout
,
Control.getBorderWidth()
,
Control.getBounds()
,
Control.getSize()
,
Control.pack(boolean)
,
"computeTrim, getClientArea for controls that implement them"
Copyright (c) EclipseSource and others 2002, 2020.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0