789
789

Reputation: 738

SWT: how to start a new line in a label?

I want to make a label that will contain a few strings, each one in a new line. For example: how to make label.setText(srt1/nstr2); look like this :

string1

string2

I've tried to use /n but it doesn't work. so, what should I do it?

Upvotes: 2

Views: 3950

Answers (1)

Monikka
Monikka

Reputation: 528

This worked for me. See if this helps.

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class MultiLineLabel {

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

        Label l = new Label(shell, SWT.WRAP);
        l.setText("First Line\nSecond Line");

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

enter image description here

Upvotes: 7

Related Questions