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

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

Introduction

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

Prototype

public StyledText(Composite parent, int style) 

Source Link

Document

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Usage

From source file:StyledTextReplaceTextRange.java

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("12345");

    styledText.replaceTextRange(2, 3, "A");

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

From source file:StyledTextClipboard.java

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

    StyledText text1 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
    StyledText text2 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);

    text1.setText("1234567");

    text1.setSelectionRange(2, 4);//from w w  w  . j  ava  2  s  . co  m

    text1.cut();
    text2.paste();

    text1.setBounds(10, 10, 100, 100);

    text2.setBounds(10, 300, 100, 100);

    shell.open();
    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 ww.  j a  v a  2 s.  c  om
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();

}

From source file:StyledTextSetKeyBinding.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.setKeyBinding('i' | SWT.ALT, ST.TOGGLE_OVERWRITE);

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

}

From source file:StyledTextClearKeyBinding.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.setKeyBinding('i' | SWT.ALT, ST.TOGGLE_OVERWRITE);

    //clear/*  www  .  jav  a2  s. co  m*/
    styledText.setKeyBinding('i' | SWT.ALT, SWT.NULL);

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

}

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);//from   ww  w.  ja  v a 2  s  .c  o m

    styledText.setBounds(10, 10, 500, 100);
    shell.open();
    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);// w ww . ja v  a 2s  .  c o  m

    styledText.replaceStyleRanges(5, 9, ranges);

    styledText.setBounds(10, 10, 500, 100);
    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;//  w w  w  . j av a  2 s  . 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:CompareStyleRange.java

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("12345");

    // Use the empty constructor and set the fields
    StyleRange sr1 = new StyleRange();
    sr1.start = 7;// ww  w. j av  a 2s. c  o m
    sr1.length = 14;
    sr1.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    sr1.background = display.getSystemColor(SWT.COLOR_WHITE);
    sr1.fontStyle = SWT.BOLD;

    // Use the constructor that accepts the fields
    StyleRange sr2 = new StyleRange(7, 14, display.getSystemColor(SWT.COLOR_GREEN),
            display.getSystemColor(SWT.COLOR_WHITE), SWT.BOLD);

    System.out.println(sr2.similarTo(sr1));

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

From source file:StyledTextThrowEAway.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.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent event) {
            // If the text contains E or e, throw it all away
            if (event.text.indexOf('e') > -1 || event.text.indexOf('E') > -1) {
                event.text = "";
            }/*  ww  w  .j  a v a  2s .c om*/
        }
    });

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