How to add Hyperlink in SWT Table`s column?

后端 未结 3 1274
终归单人心
终归单人心 2021-01-05 14:28

How to add Hyperlink in SWT Table column ? I`m using org.eclipse.swt.widgets.Table class.

Is there any way to do this without using TableViewer, JFace ?

I tr

相关标签:
3条回答
  • 2021-01-05 14:46

    You need to set the size of the editor:

    editor.grabHorizontal = true;
    //or
    editor.minimumWidth = 50;
    
    0 讨论(0)
  • 2021-01-05 14:58

    Below is one way to draw the hyperlink using TableView with a LabelProvider, as mentioned in Tonny Madsen's answer.

    The code below just paints the hyperlink.

        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);
        }
    }
    
    0 讨论(0)
  • 2021-01-05 15:02

    Yes, that is certainly possible. To do this you have to implement SWT.ItemPaint (and possibly also SWT.ItemErase and SWT.ItemMeassure).

    It is easier with TableView though if you use the correct LabelProvider...

    0 讨论(0)
提交回复
热议问题