Example usage for org.eclipse.swt.custom StyledText setStyleRanges

List of usage examples for org.eclipse.swt.custom StyledText setStyleRanges

Introduction

In this page you can find the example usage for org.eclipse.swt.custom StyledText setStyleRanges.

Prototype

public void setStyleRanges(StyleRange[] ranges) 

Source Link

Document

Sets styles to be used for rendering the widget content.

Usage

From source file:StyleRangeSetArray.java

License:asdf

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null);
    ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null);

    styledText.setStyleRanges(ranges);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();/*from w  w  w .  j  a v  a 2 s. com*/
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:ReplaceStyleRanges.java

License:asdf

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);

    final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER);
    styledText.setText("asdfasdfasdfasdf12345678910234567890");

    StyleRange[] ranges = new StyleRange[2];
    ranges[0] = new StyleRange(0, 3, display.getSystemColor(SWT.COLOR_GREEN), null);
    ranges[1] = new StyleRange(3, 6, display.getSystemColor(SWT.COLOR_BLUE), null);

    styledText.setStyleRanges(ranges);

    styledText.replaceStyleRanges(5, 9, ranges);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();//from w w w.j  av  a  2  s . c  om
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}