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

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

Introduction

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

Prototype

public String getLine(int lineIndex) 

Source Link

Document

Returns the line at the given line index without delimiters.

Usage

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

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 369");
    shell.setLayout(new FillLayout());
    shell.setText("Line spacing provider in action");

    StyledText text = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL);
    text.setText("// Type your custom line spacing \n10\n5\nabcd\n20\nefgh");

    text.setLineSpacingProvider(lineIndex -> {
        String line = text.getLine(lineIndex).trim();
        try {/*from   w  w  w  . ja va 2  s  .  c o m*/
            return Integer.parseInt(line);
        } catch (NumberFormatException e) {
            return null;
        }
    });

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