我需要在Eclipse RCP中爲樹組件實現自定義列。像Combo這樣的列或可以顯示另一個選擇對話框的選擇按鈕。默認情況下,Eclipse樹列僅支持原始文本字符串。我想用另一個控件替換簡單的TextBox(或標籤)。我怎樣才能做到這一點? 以下示例實現了一個簡單的文本單元格。如何在Eclipse RCP中實現自定義樹列和單元格
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.BORDER);
table.setHeaderVisible(true);
table.setLinesVisible(true);
for (int i = 0; i < 2; i++) {
new TableColumn(table, SWT.NONE);
}
table.getColumn(0).setText ("Task");
table.getColumn(1).setText ("Progress");
for (int i = 0; i < 40; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText("Task " + i);
}
table.getColumn(0).pack();
table.getColumn(1).setWidth(128);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
這實際上是一個SWT應用程序,而不是Eclipse RCP或插件。對於Eclipse,您可以將JFace TableViewer與OwnerDrawLabelProvider一起使用,對於SWT,您可以使用SWT.MeasureItem/PaintItem/EraseItem。 –