Constructs a new instance of this class given its parent table 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>
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> When <code>widgetSelected</code> is called, the item field of the event object is valid. If the receiver has <code>SWT.CHECK</code> style set and the check selection changes, the event object detail field contains the value <code>SWT.CHECK</code>. <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. </p>
Returns the background color that the receiver will use to draw.
Returns the column over which the TableCursor is positioned.
Returns the foreground color that the receiver will use to draw.
Returns the row over which the TableCursor is positioned.
Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.
Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null. <p> Note: This operation is a hint and may be overridden by the platform. For example, on Windows the background of a Button cannot be changed. </p> @param color the new color (or null)
Sets the receiver's foreground color to the color specified by the argument, or to the default system color for the control if the argument is null. <p> Note: This operation is a hint and may be overridden by the platform. </p> @param color the new color (or null)
Positions the TableCursor over the cell at the given row and column in the parent table.
Positions the TableCursor over the cell at the given row and column in the parent table.
Fills the interior of the rectangle specified by the arguments, with the receiver's background.
Returns the caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p>
Returns the IME.
Scrolls a rectangular area of the receiver by first copying the source area to the destination and then causing the area of the source which is not covered by the destination to be repainted. Children that intersect the rectangle are optionally moved during the operation. In addition, outstanding paint events are flushed before the source area is copied to ensure that the contents of the canvas are drawn correctly.
Sets the receiver's caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p> @param caret the new caret for the receiver, may be null
Sets the receiver's IME.
A TableCursor provides a way for the user to navigate around a Table using the keyboard. It also provides a mechanism for selecting an individual cell in a table.
<p> Here is an example of using a TableCursor to navigate to a cell and then edit it.
<code><pre> public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout());
// create a a table with 3 columns and fill with data final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); table.setLayoutData(new GridData(GridData.FILL_BOTH)); TableColumn column1 = new TableColumn(table, SWT.NONE); TableColumn column2 = new TableColumn(table, SWT.NONE); TableColumn column3 = new TableColumn(table, SWT.NONE); for (int i = 0; i < 100; i++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "cell "+i+" 0", "cell "+i+" 1", "cell "+i+" 2"}); } column1.pack(); column2.pack(); column3.pack();
// create a TableCursor to navigate around the table final TableCursor cursor = new TableCursor(table, SWT.NONE); // create an editor to edit the cell when the user hits "ENTER" // while over a cell in the table final ControlEditor editor = new ControlEditor(cursor); editor.grabHorizontal = true; editor.grabVertical = true;
cursor.addSelectionListener(new SelectionAdapter() { // when the TableEditor is over a cell, select the corresponding row in // the table public void widgetSelected(SelectionEvent e) { table.setSelection(new TableItem[] {cursor.getRow()}); } // when the user hits "ENTER" in the TableCursor, pop up a text editor so that // they can change the text of the cell public void widgetDefaultSelected(SelectionEvent e){ final Text text = new Text(cursor, SWT.NONE); TableItem row = cursor.getRow(); int column = cursor.getColumn(); text.setText(row.getText(column)); text.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { // close the text editor and copy the data over // when the user hits "ENTER" if (e.character is SWT.CR) { TableItem row = cursor.getRow(); int column = cursor.getColumn(); row.setText(column, text.getText()); text.dispose(); } // close the text editor when the user hits "ESC" if (e.character is SWT.ESC) { text.dispose(); } } }); editor.setEditor(text); text.setFocus(); } }); // Hide the TableCursor when the user hits the "MOD1" or "MOD2" key. // This allows the user to select multiple items in the table. cursor.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode is SWT.MOD1 || e.keyCode is SWT.MOD2 || (e.stateMask & SWT.MOD1) !is 0 || (e.stateMask & SWT.MOD2) !is 0) { cursor.setVisible(false); } } }); // Show the TableCursor when the user releases the "MOD2" or "MOD1" key. // This signals the end of the multiple selection task. table.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.keyCode is SWT.MOD1 && (e.stateMask & SWT.MOD2) !is 0) return; if (e.keyCode is SWT.MOD2 && (e.stateMask & SWT.MOD1) !is 0) return; if (e.keyCode !is SWT.MOD1 && (e.stateMask & SWT.MOD1) !is 0) return; if (e.keyCode !is SWT.MOD2 && (e.stateMask & SWT.MOD2) !is 0) return;
TableItem[] selection = table.getSelection(); TableItem row = (selection.length is 0) ? table.getItem(table.getTopIndex()) : selection[0]; table.showItem(row); cursor.setSelection(row, 0); cursor.setVisible(true); cursor.setFocus(); } });
shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } </pre></code>
<dl> <dt><b>Styles:</b></dt> <dd>BORDER</dd> <dt><b>Events:</b></dt> <dd>Selection, DefaultSelection</dd> </dl>
@since 2.0
@see <a href="http://www.eclipse.org/swt/snippets/#tablecursor">TableCursor snippets</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>