[英]Add hyperlink as a TableItem SWT
How can I add a hyperlink to a SWT Table? 如何将超链接添加到SWT表?
I need to have a table with ordinary TableItem objects as its rows, but sometimes I need to have a hyperlink there, so that someone can click on it open the linked page from application level. 我需要一个具有普通TableItem对象作为其行的表,但是有时我需要在其中具有超链接,以便某人可以单击它以从应用程序级别打开链接的页面。
Any tips on how to achieve this? 有关如何实现此目标的任何提示?
Here is my answer to your question: Instead of a Button
, add a Hyperlink
. 这是我对您的问题的回答:添加一个
Hyperlink
而不是Button
。
SWT - Tableviewer adding a remove button to a column in the table SWT-Tableviewer将删除按钮添加到表中的列
As an alternative to sambi reddy's answer, you can use a StyledCellLabelProvider
(if you switch to a TableViewer
) for your column and use a StyledString
to represent your link. 作为sambi reddy答案的替代方法,您可以为列使用
StyledCellLabelProvider
(如果切换到TableViewer
),并使用StyledString
表示您的链接。 Of course, you will have to handle the mouse events yourself. 当然,您将必须自己处理鼠标事件。
Here is an example: 这是一个例子:
// Column for the link
TableViewerColumn col2 = createTableViewerColumn("Link", 100, 1, viewer);
col2.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell)
{
Object element = cell.getElement();
if(element instanceof Person)
{
Person person = (Person) cell.getElement();
/* make text look like a link */
StyledString text = new StyledString();
StyleRange myStyledRange = new StyleRange(0, person.getLocation().length(), Display.getCurrent().getSystemColor(SWT.COLOR_BLUE), null);
myStyledRange.underline = true;
text.append(person.getLocation(), StyledString.DECORATIONS_STYLER);
cell.setText(text.toString());
StyleRange[] range = { myStyledRange };
cell.setStyleRanges(range);
super.update(cell);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.