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

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

Introduction

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

Prototype

public void setStyleRange(StyleRange range) 

Source Link

Document

Adds the specified style.

Usage

From source file:TextBold.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    StyleRange style1 = new StyleRange();
    style1.start = 0;// w  ww.j a  va  2  s . c o  m
    style1.length = 10;
    style1.fontStyle = SWT.BOLD;
    text.setStyleRange(style1);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextForeground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    StyleRange style1 = new StyleRange();
    style1.start = 0;/*w ww  .  ja v a2 s .com*/
    style1.length = 10;
    style1.foreground = display.getSystemColor(SWT.COLOR_RED);
    text.setStyleRange(style1);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextBackground.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    StyleRange style1 = new StyleRange();
    style1.start = 0;/* w ww  . j  a v a2s.  c o m*/
    style1.length = 10;
    style1.background = display.getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(style1);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextStrikeout.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText with underline and strike through");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");

    // make 0123456789 appear strikeout
    StyleRange style1 = new StyleRange();
    style1.start = 0;/*from w  w w .j a v a 2s . co m*/
    style1.length = 10;
    style1.strikeout = true;
    text.setStyleRange(style1);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextUnderlined.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText with underline and strike through");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");

    // make 0123456789 appear underlined
    StyleRange style1 = new StyleRange();
    style1.start = 0;/*from www  . j  a v  a2 s .  c o  m*/
    style1.length = 10;
    style1.underline = true;
    text.setStyleRange(style1);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Snippet163.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
    // make 0123456789 appear bold
    StyleRange style1 = new StyleRange();
    style1.start = 0;/*from w w  w . ja  v  a2  s .c  om*/
    style1.length = 10;
    style1.fontStyle = SWT.BOLD;
    text.setStyleRange(style1);
    // make ABCDEFGHIJKLM have a red font
    StyleRange style2 = new StyleRange();
    style2.start = 11;
    style2.length = 13;
    style2.foreground = display.getSystemColor(SWT.COLOR_RED);
    text.setStyleRange(style2);
    // make NOPQRSTUVWXYZ have a blue background
    StyleRange style3 = new StyleRange();
    style3.start = 25;
    style3.length = 13;
    style3.background = display.getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(style3);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet163.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 163");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
    // make 0123456789 appear bold
    StyleRange style1 = new StyleRange();
    style1.start = 0;//from   www  .j  a v  a2 s.c o m
    style1.length = 10;
    style1.fontStyle = SWT.BOLD;
    text.setStyleRange(style1);
    // make ABCDEFGHIJKLM have a red font
    StyleRange style2 = new StyleRange();
    style2.start = 11;
    style2.length = 13;
    style2.foreground = display.getSystemColor(SWT.COLOR_RED);
    text.setStyleRange(style2);
    // make NOPQRSTUVWXYZ have a blue background
    StyleRange style3 = new StyleRange();
    style3.start = 25;
    style3.length = 13;
    style3.background = display.getSystemColor(SWT.COLOR_BLUE);
    text.setStyleRange(style3);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet189.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText with underline and strike through");
    shell.setLayout(new FillLayout());
    StyledText text = new StyledText(shell, SWT.BORDER);
    text.setText("0123456789 ABCDEFGHIJKLM NOPQRSTUVWXYZ");
    // make 0123456789 appear underlined
    StyleRange style1 = new StyleRange();
    style1.start = 0;/*from w  w w. ja  v a  2 s.  c  o m*/
    style1.length = 10;
    style1.underline = true;
    text.setStyleRange(style1);
    // make ABCDEFGHIJKLM have a strike through
    StyleRange style2 = new StyleRange();
    style2.start = 11;
    style2.length = 13;
    style2.strikeout = true;
    text.setStyleRange(style2);
    // make NOPQRSTUVWXYZ appear underlined and have a strike through
    StyleRange style3 = new StyleRange();
    style3.start = 25;
    style3.length = 13;
    style3.underline = true;
    style3.strikeout = true;
    text.setStyleRange(style3);
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:StyleRangeStyledTextSet.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");

    // Use the empty constructor and set the fields
    StyleRange sr1 = new StyleRange();
    sr1.start = 7;//from   w  w  w . ja v a2s  . c o  m
    sr1.length = 14;
    sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    sr1.background = display.getSystemColor(SWT.COLOR_WHITE);
    sr1.fontStyle = SWT.BOLD;

    styledText.setStyleRange(sr1);

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet357.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 357");
    shell.setLayout(new FillLayout());

    final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI);
    text.setText("The quick brown fox jumps over the lazy dog.\nThat's all folks!");
    TextStyle textStyle = new TextStyle(new Font(display, "Courier", 12, SWT.BOLD),
            display.getSystemColor(SWT.COLOR_RED), null);
    textStyle.strikeout = true;/* ww  w.  ja  v  a2  s  .  c  o  m*/
    textStyle.underline = true;
    textStyle.underlineStyle = SWT.UNDERLINE_SINGLE;
    text.setStyleRanges(new int[] { 4, 5 }, new StyleRange[] { new StyleRange(textStyle) });

    text.getAccessible().addAccessibleEditableTextListener(new AccessibleEditableTextAdapter() {
        @Override
        public void setTextAttributes(AccessibleTextAttributeEvent e) {
            TextStyle textStyle = e.textStyle;
            if (textStyle != null) {
                /* Copy all of the TextStyle fields into the new StyleRange. */
                StyleRange style = new StyleRange(textStyle);
                /* Create new graphics resources because the old ones are only valid during the event. */
                if (textStyle.font != null)
                    style.font = new Font(display, textStyle.font.getFontData());
                if (textStyle.foreground != null)
                    style.foreground = new Color(display, textStyle.foreground.getRGB());
                if (textStyle.background != null)
                    style.background = new Color(display, textStyle.background.getRGB());
                if (textStyle.underlineColor != null)
                    style.underlineColor = new Color(display, textStyle.underlineColor.getRGB());
                if (textStyle.strikeoutColor != null)
                    style.strikeoutColor = new Color(display, textStyle.strikeoutColor.getRGB());
                if (textStyle.borderColor != null)
                    style.borderColor = new Color(display, textStyle.borderColor.getRGB());
                /* Set the StyleRange into the StyledText. */
                style.start = e.start;
                style.length = e.end - e.start;
                text.setStyleRange(style);
                e.result = ACC.OK;
            } else {
                text.setStyleRanges(e.start, e.end - e.start, null, null);
            }
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}