Question

I'm working on the SWT StyledText widget. I tried the setStyleRanges() approach and the LineStyleListener approach by providing text.

Now I'm wondering if there could be a possibility to use StyledText not with a String as input but with custom objects and then make this Styledtext able to automatically update when one of the custom objects changes.

For example, I would have a Content class which would have a text property and a boolean property (isBold). I would set a list of Content objects as input for the StyledText and when one of them has its isBold property set to true, the StyledText would be refreshed and the text font would be set to bold.

Is it possible?

Était-ce utile?

La solution

No I don't think so. You can use a TextViewer and add change listeners on its document to make your job easier so that you only apply style ranges to the newly added modifications. But you will need to set the style ranges yourself.

TextViewer viewer = new TextViewer();
viewer.getDocument().addDocumentListener(new IDocumentListener() {
    @Override
    public void documentChanged(final DocumentEvent event) {
        // use event.fText, event.fOffset etc to apply changes to document
        ...
    }
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top