public class Table extends Composite
The item children that may be added to instances of this class
must be of type TableItem.
Style VIRTUAL is used to create a Table whose
TableItems are to be populated by the client on an on-demand basis
instead of up-front. This can provide significant performance improvements for
tables that are very large or for which TableItem population is
expensive (for example, retrieving values from an external source).
Here is an example of using a Table with style VIRTUAL:
final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER);
table.setItemCount (1000000);
table.addListener (SWT.SetData, new Listener () {
public void handleEvent (Event event) {
TableItem item = (TableItem) event.item;
int index = table.indexOf (item);
item.setText ("Item " + index);
System.out.println (item.getText ());
}
});
Note that although this class is a subclass of Composite,
it does not make sense to add Control children to it,
or set a layout on it.
Note: Only one of the styles SINGLE, and MULTI may be specified.
IMPORTANT: This class is not intended to be subclassed.
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ALWAYS_HIDE_SELECTION
IMPORTANT: This field is not part of the SWT
public API.
|
| Constructor and Description |
|---|
Table(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 |
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. |
void |
changed(Control[] changed)
Clears any data that has been cached by a Layout for all widgets that
are in the parent hierarchy of the changed control up to and including the
receiver.
|
void |
clear(int index)
Clears the item at the given zero-relative index in the receiver.
|
void |
clear(int[] indices)
Clears the items at the given zero-relative indices in the receiver.
|
void |
clear(int start,
int end)
Removes the items from the receiver which are between the given
zero-relative start and end indices (inclusive).
|
void |
clearAll()
Clears all the items in the receiver.
|
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. |
TableColumn |
getColumn(int index)
Returns the column at the given, zero-relative index in the
receiver.
|
int |
getColumnCount()
Returns the number of columns contained in the receiver.
|
int[] |
getColumnOrder()
Returns an array of zero-relative integers that map
the creation order of the receiver's items to the
order in which they are currently being displayed.
|
TableColumn[] |
getColumns()
Returns an array of
TableColumns which are the
columns in the receiver. |
int |
getGridLineWidth()
Returns the width in pixels of a grid line.
|
Color |
getHeaderBackground()
Returns the header background color.
|
Color |
getHeaderForeground()
Returns the header foreground color.
|
int |
getHeaderHeight()
Returns the height of the receiver's header
|
boolean |
getHeaderVisible()
Returns
true if the receiver's header is visible,
and false otherwise. |
TableItem |
getItem(int index)
Returns the item at the given, zero-relative index in the
receiver.
|
TableItem |
getItem(Point point)
Returns the item at the given point in the receiver
or null if no such item exists.
|
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 receiver's.
|
TableItem[] |
getItems()
Returns a (possibly empty) array of
TableItems which
are the items in the receiver. |
boolean |
getLinesVisible()
Returns
true if the receiver's lines are visible,
and false otherwise. |
TableItem[] |
getSelection()
Returns an array of
TableItems 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.
|
TableColumn |
getSortColumn()
Returns the column which shows the sort indicator for
the receiver.
|
int |
getSortDirection()
Returns the direction of the sort indicator for the receiver.
|
int |
getTopIndex()
Returns the zero-relative index of the item which is currently
at the top of the receiver.
|
int |
indexOf(TableColumn tableColumn)
Searches the receiver's list starting at the first column
(index 0) until a column is found that is equal to the
argument, and returns the index of that column.
|
int |
indexOf(TableItem item)
Searches the receiver's list starting at the first item
(index 0) 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's list 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 |
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.
|
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 |
setColumnOrder(int[] order)
Sets the order that the items in the receiver should
be displayed in to the given argument which is described
in terms of the zero-relative ordering of when the items
were added.
|
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 |
setHeaderBackground(Color color)
Sets the header background color to the color specified
by the argument, or to the default system color if the argument is null.
|
void |
setHeaderForeground(Color color)
Sets the header foreground color to the color specified
by the argument, or to the default system color if the argument is null.
|
void |
setHeaderVisible(boolean headerVisible)
Marks the receiver's header as visible if the argument is
true,
and marks it invisible otherwise. |
void |
setItemCount(int count)
Sets the number of items contained in the receiver.
|
void |
setLinesVisible(boolean linesVisible)
Marks the receiver's lines as visible if the argument is
true,
and marks it invisible otherwise. |
void |
setSelection(int index)
Selects the item at the given zero-relative index in the receiver.
|
void |
setSelection(int[] indices)
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(TableItem item)
Sets the receiver's selection to the given item.
|
void |
setSelection(TableItem[] items)
Sets the receiver's selection to be the given array of items.
|
void |
setSortColumn(TableColumn column)
Sets the column used by the sort indicator for the receiver.
|
void |
setSortDirection(int direction)
Sets the direction of the sort indicator for the receiver.
|
void |
setTopIndex(int topIndex)
Sets the zero-relative index of the item which is currently
at the top of the receiver.
|
void |
showColumn(TableColumn column)
Shows the column.
|
void |
showItem(TableItem item)
Shows the item.
|
void |
showSelection()
Shows the selection.
|
getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabListcomputeTrim, getClientArea, getHorizontalBar, getVerticalBaraddControlListener, 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, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, updateaddDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toStringpublic static final java.lang.String ALWAYS_HIDE_SELECTION
public Table(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,
SWT.CHECK,
SWT.FULL_SELECTION,
SWT.HIDE_SELECTION,
SWT.VIRTUAL,
Widget.checkSubclass(),
Widget.getStyle()public <T> T getAdapter(java.lang.Class<T> adapter)
WidgetAdaptable 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 AdaptablegetAdapter in class Compositeadapter - the lookup classnull if
there is no adapter associated with the given class.public void setData(java.lang.String key,
java.lang.Object value)
WidgetApplications 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 Controlkey - the name of the propertyvalue - the new value for the propertyWidget.getData(String)public int getColumnCount()
TableColumns were created by the programmer,
this value is zero, despite the fact that visually, one column
of items may be visible. This occurs when the programmer uses
the table like a list, adding items but never creating a column.SWTException - public TableColumn[] getColumns()
TableColumns which are the
columns in the receiver. Columns are returned in the order
that they were created. If no TableColumns were
created by the programmer, the array is empty, despite the fact
that visually, one column of items may be visible. This occurs
when the programmer uses the table like a list, adding items but
never creating a column.
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 - getColumnOrder(),
setColumnOrder(int[]),
TableColumn.getMoveable(),
TableColumn.setMoveable(boolean),
SWT.Movepublic TableColumn getColumn(int index)
TableColumns were created by the programmer,
this method will throw ERROR_INVALID_RANGE despite
the fact that a single column of data may be visible in the table.
This occurs when the programmer uses the table like a list, adding
items but never creating a column.index - the index of the column to returnjava.lang.IllegalArgumentException - SWTException - getColumnOrder(),
setColumnOrder(int[]),
TableColumn.getMoveable(),
TableColumn.setMoveable(boolean),
SWT.Movepublic int indexOf(TableColumn tableColumn)
tableColumn - the search columnjava.lang.IllegalArgumentException - SWTException - public void setColumnOrder(int[] order)
order - the new order to display the itemsSWTException - java.lang.IllegalArgumentException - getColumnOrder(),
TableColumn.getMoveable(),
TableColumn.setMoveable(boolean),
SWT.Movepublic int[] getColumnOrder()
Specifically, the indices of the returned array represent the current visual order of the items, and the contents of the array represent the creation order of the items.
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 - setColumnOrder(int[]),
TableColumn.getMoveable(),
TableColumn.setMoveable(boolean),
SWT.Movepublic void setItemCount(int count)
count - the number of itemsSWTException - public int getItemCount()
SWTException - public TableItem[] getItems()
TableItems 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 TableItem getItem(int index)
index - the index of the item to returnjava.lang.IllegalArgumentException - SWTException - public TableItem getItem(Point point)
The item that is returned represents an item that could be selected by the user. For example, if selection only occurs in items in the first column, then null is returned if the point is outside of the item. Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, determines the extent of the selection.
point - the point used to locate the itemjava.lang.IllegalArgumentException - SWTException - public int indexOf(TableItem item)
item - the search itemjava.lang.IllegalArgumentException - SWTException - public void removeAll()
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 index)
index - the index for the itemjava.lang.IllegalArgumentException - SWTException - public void remove(int[] indices)
indices - the array of indices of the itemsjava.lang.IllegalArgumentException - SWTException - public void clear(int index)
SWT.VIRTUAL style,
these attributes are requested again as needed.index - the index of the item to clearjava.lang.IllegalArgumentException - SWTException - SWT.VIRTUAL,
SWT.SetDatapublic void clear(int start,
int end)
SWT.VIRTUAL style,
these attributes are requested again as needed.start - the start index of the item to clearend - the end index of the item to clearjava.lang.IllegalArgumentException - SWTException - SWT.VIRTUAL,
SWT.SetDatapublic void clearAll()
SWT.VIRTUAL style, these
attributes are requested again as needed.SWTException - SWT.VIRTUAL,
SWT.SetDatapublic void clear(int[] indices)
SWT.VIRTUAL style,
these attributes are requested again as needed.indices - the array of indices of the itemsjava.lang.IllegalArgumentException - SWTException - SWT.VIRTUAL,
SWT.SetDatapublic int getSelectionIndex()
SWTException - public void setSelection(int index)
index - the index of the item to selectSWTException - deselectAll(),
select(int)public int getSelectionCount()
SWTException - 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 TableItem[] getSelection()
TableItems 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 void setSelection(int[] indices)
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 indices of the items to selectjava.lang.IllegalArgumentException - SWTException - deselectAll(),
select(int[])public void setSelection(TableItem item)
If the item is not in the receiver, then it is ignored.
item - the item to selectjava.lang.IllegalArgumentException - SWTException - public void setSelection(TableItem[] items)
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.
items - the array of itemsjava.lang.IllegalArgumentException - SWTException - deselectAll(),
select(int[]),
setSelection(int[])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 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 select(int index)
index - the index of the item to selectSWTException - 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 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 selectAll()
If the receiver is single-select, do nothing.
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 void deselectAll()
SWTException - public void setTopIndex(int topIndex)
topIndex - the index of the top itemSWTException - public int getTopIndex()
SWTException - public void showItem(TableItem item)
item - the item to be shownjava.lang.IllegalArgumentException - SWTException - showSelection()public void showColumn(TableColumn column)
column - the column to be shownjava.lang.IllegalArgumentException - SWTException - public void showSelection()
SWTException - showItem(TableItem)public void setHeaderVisible(boolean headerVisible)
true,
and marks it invisible otherwise.
If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
headerVisible - the new visibility stateSWTException - public boolean getHeaderVisible()
true if the receiver's header is visible,
and false otherwise.
If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.
SWTException - public void setHeaderBackground(Color color)
color - the new color (or null)java.lang.IllegalArgumentException - SWTException - public Color getHeaderBackground()
SWTException - public void setHeaderForeground(Color color)
color - the new color (or null)java.lang.IllegalArgumentException - SWTException - public Color getHeaderForeground()
SWTException - public boolean getLinesVisible()
true if the receiver's lines are visible,
and false otherwise.
If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, this method may still indicate that it is considered visible even though it may not actually be showing.
SWTException - public void setLinesVisible(boolean linesVisible)
true,
and marks it invisible otherwise.
If one of the receiver's ancestors is not visible or some other condition makes the receiver not visible, marking it visible may not actually cause it to be displayed.
linesVisible - the new visibility stateSWTException - public void setSortColumn(TableColumn column)
column - the column used by the sort indicator or nulljava.lang.IllegalArgumentException - SWTException - public TableColumn getSortColumn()
SWTException - setSortColumn(TableColumn)public void setSortDirection(int direction)
UP, DOWN or NONE.direction - the direction of the sort indicatorSWTException - public int getSortDirection()
UP, DOWN
or NONE.SWTException - setSortDirection(int)public int getItemHeight()
SWTException - public int getHeaderHeight()
SWTException - public int getGridLineWidth()
SWTException - public void addSelectionListener(SelectionListener listener)
SelectionListener
interface.
When widgetSelected is called, the item field of the event object is valid.
If the receiver has SWT.CHECK style set and the check selection changes,
the event object detail field contains the value SWT.CHECK.
widgetDefaultSelected is typically called when an item is double-clicked.
The item field of the event object is valid for default selection, but the detail field is not used.
listener - the listener which should be notifiedjava.lang.IllegalArgumentException - SWTException - SelectionListener,
removeSelectionListener(org.eclipse.swt.events.SelectionListener),
SelectionEventpublic void removeSelectionListener(SelectionListener listener)
listener - the listener which should no longer be notifiedjava.lang.IllegalArgumentException - SWTException - SelectionListener,
addSelectionListener(SelectionListener)public void setFont(Font font)
Controlpublic 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 CompositewHint - 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, 2018.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0