Adicionando componentes SWT nas células de uma tabela

 

Algumas vezes é preciso utilizar componentes SWT dentro das células de uma tabela, e isto pode ser feito através de org.eclipse.swt.custom.TableEditor.


fig01dicswt.JPG

 

Exemplo

 

A seguir está o código da imagem apresentada onde são adicionados CheckBox e ComboBox dentro de células de uma tabela.

 

Código de implementação

 

private void createTable() {

  Table table = new Table(top, SWT.NONE);
  table.setHeaderVisible(true);
  table.setLinesVisible(true);
  table.setBounds(new org.eclipse.swt.graphics.Rectangle(47,67,190,70));

  TableColumn tableColumn = new TableColumn(table, SWT.NONE);
  tableColumn.setWidth(100);
  tableColumn.setText("Check Column");

  TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
  tableColumn1.setWidth(100);
  tableColumn1.setText("Combo Column");

  TableItem tableItem=new TableItem(table,SWT.NONE);
  TableEditor editor = new TableEditor (table);

  Button checkButton = new Button(table, SWT.CHECK);
  checkButton.pack();

  editor.minimumWidth = checkButton.getSize ().x;
  editor.horizontalAlignment = SWT.CENTER;
  editor.setEditor(checkButton, tableItem, 0);
  editor = new TableEditor (table);

  Combo combo = new Combo(table, SWT.CHECK);
  combo.pack();

  editor.minimumWidth = combo.getSize ().x;
  editor.horizontalAlignment = SWT.CENTER;
  editor.setEditor(combo, tableItem, 1);

}