SWT标签和Clabel无法正确呈现'&'字符

问题描述 投票:0回答:1

我正在尝试使用SWT标签/ Clabel显示&在我的字符串中,但是它们都忽略了&字符。下面是可以重现此问题的相同代码

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

 public class LabelDemo {
   public static void main(String[] args) {
     final Display display = new Display();
     final Shell shell = new Shell(display, SWT.SHELL_TRIM);
     shell.setLayout(new FillLayout());
 Label label=new Label(shell, SWT.BORDER);
     label.setText("text &the label");

    // label.setImage(new Image(display,"yourFile.gif"));
     shell.open();
     // Set up the event loop.
     while (!shell.isDisposed()) {
       if (!display.readAndDispatch()) {
         // If no more entries in event queue
         display.sleep();
       }
     }
     display.dispose();
   }

 }

我在这里做错什么了吗,任何线索都会有所帮助。

swt rcp
1个回答
0
投票
[我想我发现了根本原因,为什么它跳过了标签中的&或助记符。我们需要通过添加一个多余的&使其转义,以使其得以呈现]]
© www.soinside.com 2019 - 2024. All rights reserved.