Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a Button to JFace Table

Tags:

swt

jface

How can I insert a SWT Button control into JFace TableViewer ?

like image 533
faraday Avatar asked Mar 07 '26 12:03

faraday


1 Answers

The answer given is nice a nice way to implement your own buttons with custom drawings, in or outside the a table. However, you can put SWT controls in JFace Tables.

http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/PlacearbitrarycontrolsinaSWTtable.htm

The solution for building a table with columns containing comboboxes, text fields, and buttons provided by the link is:

Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
table.setLinesVisible(true);
for (int i = 0; i < 3; i++) {
  TableColumn column = new TableColumn(table, SWT.NONE);
  column.setWidth(100);
}
for (int i = 0; i < 12; i++) {
  new TableItem(table, SWT.NONE);
}
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
  TableEditor editor = new TableEditor(table);
  CCombo combo = new CCombo(table, SWT.NONE);
  editor.grabHorizontal = true;
  editor.setEditor(combo, items[i], 0);
  editor = new TableEditor(table);
  Text text = new Text(table, SWT.NONE);
  editor.grabHorizontal = true;
  editor.setEditor(text, items[i], 1);
  editor = new TableEditor(table);
  Button button = new Button(table, SWT.CHECK);
  button.pack();
  editor.minimumWidth = button.getSize().x;
  editor.horizontalAlignment = SWT.LEFT;
  editor.setEditor(button, items[i], 2);
}
like image 174
Kirby Avatar answered Mar 10 '26 02:03

Kirby