简体   繁体   中英

How to set focus on an SWT TableItem

I have an add Button, which adds rows to an SWT table and i implemented TableEditor to edit the rows.

Button button = new Button(composite, SWT.NONE);
  button.addSelectionListener(new SelectionAdapter() {
     @Override
     public void widgetSelected(SelectionEvent e) {
        TableItem item = new TableItem(table, SWT.NONE);
                }
  });

and this is the piece of code for table creation

table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION);
  table.setBounds(0, 0, 240, 160);
  toolkit.adapt(table);
  toolkit.paintBordersFor(table);
  table.setHeaderVisible(true);
  table.setLinesVisible(true);

When the user hits the add button, a row is created allowing the user to edit. But from a user point of view, its not visible that row is created or not, until and unless he selects that row and editor is enabled.

So can you please suggest on how to set focus on the newly added TableItem?

See Table.setSelection() and Table.showItem() API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM