12dollar
12dollar

Reputation: 655

SWT Table only first column selected

I currently have a populated SWT table with the following styles:

    SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL

used SWT.FULL_SELECTION to get the whole line selected if clicked. but using table.getSelection() only returns the first column. I don't have any tableviewer or something else set.

where did I make a mistake?

edit: example:

if (table.getSelectionCount() > 0) {
  for (TableItem item : table.getSelection()) {
    System.out.println(item);
  }
}

this returns only the first column

Upvotes: 0

Views: 905

Answers (1)

Baz
Baz

Reputation: 36904

Since you are only calling System.out.println() on the whole TableItem, Java will internally use TableItem#toString() to convert it to a String.

The resulting string however, will not contain all the data of the TableItem.

Instead, you'll need to iterate over the columns to get the data using TableItem#getText(int column):

for(int i = 0; i < table.getColumnCount(); i++)
    System.out.println(item.getText(i));

Upvotes: 1

Related Questions