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

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

Introduction

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

Prototype

public Rectangle getClientArea() 

Source Link

Document

Returns a rectangle which describes the area of the receiver which is capable of displaying data (that is, not covered by the "trimmings").

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);/*from w  w  w . j a v  a 2  s  .co 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  a  2 s .c  om*/
    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();
}