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

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

Introduction

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

Prototype

public void setForeground(Color color) 

Source Link

Usage

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

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Snippet 218");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setText(text);// w w  w .  ja v a  2s. c  o m
    FontData data = display.getSystemFont().getFontData()[0];
    Font font = new Font(display, data.getName(), 16, SWT.BOLD);
    styledText.setFont(font);
    styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    styledText.addListener(SWT.Resize, event -> {
        Rectangle rect = styledText.getClientArea();
        Image newImage = new Image(display, 1, Math.max(1, rect.height));
        GC gc = new GC(newImage);
        gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
        gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
        gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
        gc.dispose();
        styledText.setBackgroundImage(newImage);
        if (oldImage != null)
            oldImage.dispose();
        oldImage = newImage;
    });
    shell.setSize(700, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (oldImage != null)
        oldImage.dispose();
    font.dispose();
    display.dispose();
}

From source file:StyledTextGradientBackground.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
    styledText.setText(text);/* w  w  w . j  av  a2 s. c  o  m*/
    FontData data = display.getSystemFont().getFontData()[0];
    Font font = new Font(display, data.getName(), 16, SWT.BOLD);
    styledText.setFont(font);
    styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
    styledText.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle rect = styledText.getClientArea();
            Image newImage = new Image(display, 1, Math.max(1, rect.height));
            GC gc = new GC(newImage);
            gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
            gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
            gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
            gc.dispose();
            styledText.setBackgroundImage(newImage);
            if (oldImage != null)
                oldImage.dispose();
            oldImage = newImage;
        }
    });
    shell.setSize(700, 400);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    if (oldImage != null)
        oldImage.dispose();
    font.dispose();
    display.dispose();
}