我想制作一个包含几个字符串的标签,每个字符串都在一个新行中。
例如:如何使label.setText(srt1/nstr2);
看起来像这样:
字符串1
字符串2
我尝试使用/n
,但它不起作用。那么,我应该怎么做呢?
答案 0 :(得分: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();
}
}