SWT:如何在标签中开始新的一行?

789*_*789 1 java swt label

我想制作一个包含几个字符串的标签,每个字符串都在一个新行中.例如:如何使这样label.setText(srt1/nstr2);看起来:

STRING1

字符串2

我试过用,/n但它不起作用.那么,我应该怎么做?

Mon*_*kka 5

这对我有用.看看这是否有帮助.

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述