Mihai Galos
Mihai Galos

Reputation: 1897

SWT Label with horizontal line not showing correctly

I'm trying to display a label in a 2-columned GridLayout. I can't seem to make it work to display both text and the horizontal line underneath:

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;
}

What I'm getting is just the line with no text.

Label.png

What am I doing wrong?

Upvotes: 1

Views: 411

Answers (1)

greg-449
greg-449

Reputation: 111142

A Label with the SWT.SEPARATOR style does not display any text value. You must use a separate control to display the text.

From the Label source, showing that setText is completely ignored for SWT.SEPARATOR:

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

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

  ...

Upvotes: 1

Related Questions