Sunny V
Sunny V

Reputation: 3

create a right aligned multi line text field in swt

Is there any way to create a right aligned multi lined text field in SWT without applying SWT.WRAP style? I need to have the horizontal scroll bar in the text field which disappears when WRAP is used.

Upvotes: 0

Views: 196

Answers (1)

Baz
Baz

Reputation: 36884

Just use SWT.MULTI | SWT.RIGHT as the style for the Text:

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

    Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.RIGHT);
    text.setText("First line\nsecond line");

    shell.open();
    shell.pack();

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

Looks like this:

enter image description here

Upvotes: 2

Related Questions