【问题标题】:SWT label and Clabel does not render '&' character correctlySWT 标签和 Clabel 无法正确呈现“&”字符
【发布时间】:2020-10-06 20:28:38
【问题描述】:

我正在尝试使用 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】:

    我想我找到了它在标签中跳过 & 或助记符的根本原因。我们需要通过添加一个额外的 & 来转义它,以便它被渲染

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 2013-08-30
      • 1970-01-01
      • 2017-09-03
      相关资源
      最近更新 更多