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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Sets the widget content.

Usage

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;//from   ww w .j  av a2s .  c o  m
    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 w w  .  j  a v a2  s. c  om
    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: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 .ja  va 2  s .  c om
    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: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;// w  w  w  .j  av a  2 s  .  co  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: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  av  a 2 s .  c  o 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:StyledTextActionBound.java

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

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

    int altEAction = styledText.getKeyBinding('e' | SWT.ALT);

    styledText.setBounds(10, 10, 100, 100);
    shell.open();// ww w .j  ava  2s . co  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:StyledTextActionBoundArrowShift.java

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

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

    int shiftLeftAction = styledText.getKeyBinding(SWT.ARROW_LEFT | SWT.SHIFT);

    styledText.setBounds(10, 10, 100, 100);
    shell.open();//from w  w w . jav a  2 s  .co  m
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:StyledTextLimit.java

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

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

    styledText.setTextLimit(10);/*w  w w  . ja v a  2 s .c  o  m*/

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

}

From source file:StyledTextTabSize.java

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

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

    styledText.setTabs(2);/*  w  w  w  .j  a  v  a 2 s.c  om*/

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

}

From source file:StyledTextReadOnly.java

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

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

    styledText.setEditable(false);//from w w  w  .ja  v  a2  s. c o  m

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

}