Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在SWT表的列中添加超链接?_Java_Eclipse_Swt - Fatal编程技术网

Java 如何在SWT表的列中添加超链接?

Java 如何在SWT表的列中添加超链接?,java,eclipse,swt,Java,Eclipse,Swt,如何在SWT表格列中添加超链接? 我正在使用org.eclipse.swt.widgets.Table类 没有使用TableViewer、JFace,有没有办法做到这一点 我尝试了这种方法,但没有正常工作(没有显示超链接) for(int i=2;i是的,这当然是可能的。要做到这一点,您必须实现SWT.ItemPaint(也可能实现SWT.itemeasure和SWT.itemeasure) 使用TableView会更容易,但是如果使用正确的LabelProvider…,则需要设置编辑器的大小:

如何在SWT表格列中添加超链接? 我正在使用org.eclipse.swt.widgets.Table类

没有使用TableViewer、JFace,有没有办法做到这一点

我尝试了这种方法,但没有正常工作(没有显示超链接)


for(int i=2;i是的,这当然是可能的。要做到这一点,您必须实现
SWT.ItemPaint
(也可能实现
SWT.itemeasure
SWT.itemeasure


使用
TableView
会更容易,但是如果使用正确的
LabelProvider

,则需要设置编辑器的大小:

editor.grabHorizontal = true;
//or
editor.minimumWidth = 50;

下面是使用TableView和LabelProvider绘制超链接的一种方法,如Tony Madsen的回答中所述

下面的代码只是绘制超链接

    TableViewerColumn column = ...
    column.setLabelProvider( new MyHyperlinkLabelProvider( tableViewerFiles.getTable() ));

private final class MyHyperlinkLabelProvider extends StyledCellLabelProvider {
    MyHyperlink m_control;

    private MyHyperlinkLabelProvider( Composite parent ) {
        m_control = new MyHyperlink( parent, SWT.WRAP );
    }

    @Override 
    protected void paint( Event event, Object element ) {
        String sValue = ... [Get cell value from row element]
        m_control.setText( sValue );

        GC gc = event.gc;
        Rectangle cellRect = new Rectangle( event.x, event.y, event.width, event.height );
        cellRect.width = 4000;

        m_control.paintText( gc, cellRect);
    }
}

private class MyHyperlink extends Hyperlink {
    public MyHyperlink(Composite parent, int style) {
        super(parent, style);
        this.setUnderlined(true);
    }

    @Override
    public void paintText(GC gc, Rectangle bounds) {
        super.paintText(gc, bounds);
    }
}
    TableViewerColumn column = ...
    column.setLabelProvider( new MyHyperlinkLabelProvider( tableViewerFiles.getTable() ));

private final class MyHyperlinkLabelProvider extends StyledCellLabelProvider {
    MyHyperlink m_control;

    private MyHyperlinkLabelProvider( Composite parent ) {
        m_control = new MyHyperlink( parent, SWT.WRAP );
    }

    @Override 
    protected void paint( Event event, Object element ) {
        String sValue = ... [Get cell value from row element]
        m_control.setText( sValue );

        GC gc = event.gc;
        Rectangle cellRect = new Rectangle( event.x, event.y, event.width, event.height );
        cellRect.width = 4000;

        m_control.paintText( gc, cellRect);
    }
}

private class MyHyperlink extends Hyperlink {
    public MyHyperlink(Composite parent, int style) {
        super(parent, style);
        this.setUnderlined(true);
    }

    @Override
    public void paintText(GC gc, Rectangle bounds) {
        super.paintText(gc, bounds);
    }
}