gpt4 book ai didi

java - SWT:如何在标签中开始新行?

转载 作者:行者123 更新时间:2023-11-29 07:46:25 25 4
gpt4 key购买 nike

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

string1

string2

我试过使用 /n 但它不起作用。那么,我该怎么做呢?

最佳答案

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

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

关于java - SWT:如何在标签中开始新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25223637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com