あるプログラマの日記

プログラマのメモ、出来事、考えたこと、勉強とかの雑記

編集可能なTableのセルの実装について

テーブルの1列目がTabelItem、2列目にTextを設定する。
TextはTableEditorのsetEditer()メソッドにediterとして
設定する。
Text以外のWidgetを設定することも可能。


...
Table table = new Table (shell, SWT.BORDER);
// ヘッダを可視にする
table.setHeaderVisible (true);
// セルの分割線を表示
table.setLinesVisible(true);
for (int i=0; i<3; i++) {
TableColumn column = new TableColumn (table, SWT.NONE);
}
table.getColumn (0).setText ("Label col");
table.getColumn (1).setText ("Edit col");
for (int i=0; i<4; i++) {
TableItem item = new TableItem (table, SWT.NONE); // index 0
item.setText ("COL " + i);

Text text = new Text (table, SWT.NONE);
TableEditor editor = new TableEditor (table); // index 1
editor.grabHorizontal = editor.grabVertical = true;
editor.setEditor (text, item, 1);
}
table.getColumn (0).pack ();
table.getColumn (1).setWidth (128);
...