Mac上的Java表怪诞
我正在开发一个Eclipse插件,它使用表打印到视图中。我在各种Eclipse和Ubuntu版本上测试了系统,表中的值是可见的。i、 行适合内容。但在将其部署到Mac时,行与内容不匹配。我可以看到里面有东西,但整个内容都不可见,也无法调整大小。以下是我正在使用的代码:Mac上的Java表怪诞,java,macos,eclipse-plugin,swt,Java,Macos,Eclipse Plugin,Swt,我正在开发一个Eclipse插件,它使用表打印到视图中。我在各种Eclipse和Ubuntu版本上测试了系统,表中的值是可见的。i、 行适合内容。但在将其部署到Mac时,行与内容不匹配。我可以看到里面有东西,但整个内容都不可见,也无法调整大小。以下是我正在使用的代码: int style = SWT.NONE; Table table = new Table(composite, style); table.setHeaderVisible(true); table.setLinesVisibl
int style = SWT.NONE;
Table table = new Table(composite, style);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn col = new TableColumn(table, style);
// Is this ok?
col.setWidth(200);
col.setResizable(true);
for (int i = 0; i < contents.size(); i++){
TableItem item = new TableItem(table, style);
item.setText(contents.get(i));
}
int style=SWT.NONE;
表格=新表格(组合,样式);
表.setheadervible(true);
表.setLinesVisible(真);
TableColumn col=新的TableColumn(表格,样式);
//这样行吗?
柱设置宽度(200);
col.setresizeable(true);
对于(int i=0;i
我尝试了不同的风格,但没有运气。知道出了什么问题吗 好的,我想出了一段代码来实现这个技巧:
public class TableItemPaintListener implements Listener{
public void handleEvent(Event event) {
switch (event.type) {
case SWT.MeasureItem: {
TableItem item = (TableItem) event.item;
String text = item.getText();
Point size = event.gc.textExtent(text);
event.width = size.x;
event.height = Math.max(event.height, size.y);
break;
}
}
}
}
然后:
table.addListener(SWT.MeasureItem, new TableItemPaintListener());
基本上,我们在每个表项上触发的绘制事件上安装一个处理程序。然后,我们设置单元格高度值以适合内容