2
我發現了一些針對此問題的解決方案,但它們僅適用於RCP平臺。我正在使用RAP平臺,我無法找到解決方案。如何將圖像與表格單元格的中心對齊(SWT表格)RAP平臺
我發現了一些針對此問題的解決方案,但它們僅適用於RCP平臺。我正在使用RAP平臺,我無法找到解決方案。如何將圖像與表格單元格的中心對齊(SWT表格)RAP平臺
要自行對齊的圖像,你必須在RAP兩種選擇:
標記
相應準備表後,您可以使用HTML的一個子集與表中的項目的文本。
Table table = new Table(parent, SWT.NONE);
table.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
table.setData(RWT.CUSTOM_ITEM_HEIGHT, Integer.valueOf(80));
TableItem item = new TableItem(table, SWT.NONE);
String imageUrl = RWT.getRequest().getContextPath() + "/" + registerImage("foo.png");
item.setText("<img src='" + imageUrl + "' width='10' height='10' style='padding-right:5px'/>");
註冊一個圖像的代碼(這裏假定圖像位於類路徑上)應該是這樣的:
String registerImage(String resourceName) throws IOException {
IResourceManager resourceManager = RWT.getResourceManager();
if(!resourceManager.isRegistered(resourceName)) {
InputStream inputStream = CLASSLOADER.getResourceAsStream(resourceName);
try {
resourceManager.register(resourceName, inputStream);
} finally {
inputStream.close();
}
}
return resourceManager.getLocation(resourceName);
}
更多細節可以在這裏找到:http://eclipsesource.com/blogs/2012/09/12/making-your-images-available-using-markup/
行模板
使用行模板,可以將表的默認列布局替換爲nd項目佈局的方式可以改變。
要更改爲圖像的位置,它將像往常一樣設置爲item.setImage(...)
,然後創建一個模板以根據需要定位圖像。 最後,表格被告知使用table.setData(...)
的模板。
Template template = new Template();
ImageCell imageCell = new ImageCell(template);
imageCell.setBindingIndex(0); // bind to image from column 0
imageCell.setTop(4).setLeft(4).setWidth(48).setHeight(48);
table.setData(RWT.ROW_TEMPLATE, template);
更多關於此這裏:http://eclipsesource.com/blogs/2013/11/14/rap-2-2m3-introducing-row-templates/
看到http://stackoverflow.com/questions/8968352/how-to-align-image-to-center-of-table-cell-swt-table – flafoux
@flafoux的建議在RAP中不起作用,因爲它不支持所有者繪製的表項。 –