[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Wrapping Label

Hi all,

I have a Dialog (a subclass of ElementTreeSelectionDialog) where I have a message which is too large for a single line (its content is dynamic and includes an arbitrary path).

To get the label to wrap I had to override the method createMessageArea (from the superclass SelectionDialog) as below. Wrapping works, but the label is not wrapped when the dialog is first shown, instead the dialog is elongated to show the entire label. How can I fix this, as it looks bad? I have tried setting the widthHint of the GridData, but this seems to set a maximum width for the label which it will not grow beyond even when the dialog is resized to be larger.

Thanks in advance.

Matt D.

Overridden createMessageArea method:

/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.SelectionDialog#createMessageArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Label createMessageArea(Composite composite) {
Label label = new Label(composite, SWT.WRAP);
String message = getMessage();
if (message != null) {
label.setText(message);
}
label.setFont(composite.getFont());
GridData gd = new GridData(SWT.LEAD, SWT.CENTER, true, false);
label.setLayoutData(gd);
return label;
}