Can HTML-Style Links be added to SWT StyledText?

后端 未结 2 1913
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 12:18

I know SWT has a Link class to create HTML a href style links as widgets, but I wast trying to find a way to make certain text in a StyledText control appear and function as

2条回答
  •  無奈伤痛
    2021-01-12 12:25

    You need to add a LineStyleListener to the StyledText widget:

    textField.addLineStyleListener (...);
    
    ...
    
    public void lineGetStyle (LineStyleEvent e)
    {
      // alloc a set of styles for the requested line
      e.styles = new StyleRange [...];
    
      for (int i = 0; i < e.styles.length; i++)
      {
        StyleRange styleRange = new StyleRange ();
    
        styleRange.start = ...;
        styleRange.length = ...;
        styleRange.underline = true;
        styleRange.foreground = ;
    
        e.styles [i] = styleRange;
      }
    }
    

    The javadoc for LineStyleListener will give you some more info.

    To add the click behaviour, you need some more logic: I could also paste some code that we use to automatically add HTML-style clickable links URL's in a StyledText widget if that would help.

提交回复
热议问题