[英]How to add a String containing a line break to a swt list
I have a GUI with a org.eclipse.swt.widgets.List in it and would like to add a String that contains a line break to it. 我有一个带有org.eclipse.swt.widgets.List的GUI,并想添加一个包含换行符的String。 However, it does not work and the line break is ignored. 但是,它不起作用并且换行符被忽略。 Can anyone help? 有人可以帮忙吗? Here is my code: 这是我的代码:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
public class Test {
public static void main(String[] args) {
Display display = new Display();
final Shell myShell = new Shell(display);
myShell.setText("MyShell");
myShell.setLayout(new GridLayout(1, false));
Composite composite = new Composite(myShell, SWT.MULTI);
composite.setLayout(new GridLayout(1, false));
GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_composite.widthHint = 250;
composite.setLayoutData(gd_composite);
List mylist = new List(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
mylist.add("my" + "\n" + "String");
myShell.setSize(94, 94);
myShell.open();
while (!myShell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
The String is displayed in the list as myString . 字符串在列表中显示为myString 。 However, I'd like to display it like this: 但是,我想这样显示:
my 我的
String 串
You can't have line breaks in SWT List
widgets. SWT List
小部件中不能有换行符。 You can however use a Table
with just one column instead and make the text in the cell wrap/break. 但是,您可以使用仅包含一列的Table
,并在单元格换行/分隔符中输入文本。
There are examples here: 这里有一些例子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.