水平线无法正确显示的SWT标签

时间:2014-03-06 08:04:30

标签: java swt label

我正在尝试在2列的GridLayout中显示标签。我似乎无法显示文本和下面的水平线:

public void foo(){
     popupShell = new Shell(Display.getDefault(), SWT.NO_TRIM | SWT.ON_TOP | SWT.MODELESS);
     //popupShell.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
     popupShell.setLayout(createNoMarginLayout(2, false));

     Label history  = new Label(popupShell, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);
     history.setText("History");
     history.setVisible(true);
     Label fill  = new Label(popupShell, SWT.NONE);
     fill.setSize(0,30);
}

public static GridLayout createNoMarginLayout(int numColumns, boolean makeColumnsEqualWidth) {
     GridLayout layout = new GridLayout(numColumns, makeColumnsEqualWidth);
     layout.verticalSpacing          = 0;
     layout.horizontalSpacing   = 0;
     layout.marginTop           = 0;
     layout.marginBottom             = 0;

     layout.marginLeft               = 0;
     layout.marginRight              = 0;
     layout.marginWidth              = 0;
     layout.marginHeight             = 0;
     return layout;
}

我得到的只是没有文字的那一行。

Label.png

我做错了什么?

1 个答案:

答案 0 :(得分:1)

Label样式的SWT.SEPARATOR不会显示任何文字值。您必须使用单独的控件来显示文本。

来自Label来源,显示setText完全忽略了SWT.SEPARATOR

public void setText (String string) {
  checkWidget();
  if (string == null) error (SWT.ERROR_NULL_ARGUMENT);

  if ((style & SWT.SEPARATOR) != 0) return;

  ...