通过捕获SWT.MeasureItem事件来定制单元格的高度和宽度,具体内容可参看原文Custom Drawing Table and Tree Items,代码演示如下:
Display display = new Display(); Shell shell = new Shell(display); shell.setBounds(10, 10, 200, 250);
final Table table = new Table(shell, SWT.NONE); table.setBounds(10, 10, 150, 200); table.setLinesVisible(true);
final int rowHeight =30; for (int i = 0; i < 5; i++) { new TableItem(table, SWT.NONE).setText("item " + i); } table.addListener(SWT.MeasureItem, new Listener() { public void handleEvent(Event event) { event.height =rowHeight; } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose();
|