Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Multi Line RadioButton and Checkbox
Multi Line RadioButton and Checkbox [message #1140130] Wed, 16 October 2013 02:37 Go to next message
Matthias Nick is currently offline Matthias Nick
Messages: 148
Registered: August 2013
Senior Member
Hi,

I need to create a RadioButton/Checkbox, where the label of the RadioButton/Checkbox is multiline. In Swing I can do it by setting the value of the RadioButton/Checkbox in HTML tags. However, SWT doesn't support this way.

I am wondering how I can do it in SWT?

Can you help me?
Re: Multi Line RadioButton and Checkbox [message #1153216 is a reply to message #1140130] Thu, 24 October 2013 09:01 Go to previous message
Matthias Nick is currently offline Matthias Nick
Messages: 148
Registered: August 2013
Senior Member
Okay, I solved by creating a new custom widget. The Button is only used for the "Radio" symbol and the label is capable of displaying multiline text.
public class MultilineButton extends Composite {
  Button btn;
  Label label;

  public MultilineButton(Composite parent, int style) {
    super(parent, style);
    createContent(this, style);
    createLayout();
  }

  protected void createContent(Composite parent, int style) {
    this.btn = new ButtonEx(parent, style);
    this.label = new Label(parent, 0);
  }

  protected void createLayout() {
    GridLayout containerLayout = new GridLayout(2, false);
    containerLayout.horizontalSpacing = 5; //space between button and label
    containerLayout.marginHeight = 0;
    containerLayout.marginWidth = 0;
    containerLayout.verticalSpacing = 0;

    GridData labelData = new GridData(SWT.FILL, SWT.FILL, false, false);
    labelData.verticalIndent = 3;
    label.setLayoutData(labelData);

    GridData buttonData = new GridData(SWT.FILL, SWT.TOP, false, false);
    buttonData.verticalIndent = 3;
    btn.setLayoutData(buttonData);

    setLayout(containerLayout);
  }

  public void setText(String text) {
    label.setText(text);
  }

  @Override
  public void setFont(org.eclipse.swt.graphics.Font font) {
    label.setFont(font);
    btn.setFont(font);
  }

  @Override
  public void setForeground(org.eclipse.swt.graphics.Color color) {
    super.setForeground(color);
    label.setForeground(color);
    btn.setForeground(color);
  }

  @Override
  public void setBackground(org.eclipse.swt.graphics.Color color) {
    super.setBackground(color);
    label.setBackground(color);
    btn.setBackground(color);
  }

  @Override
  public void removeListener(int eventType, Listener listener) {
    super.removeListener(eventType, listener);
    btn.removeListener(eventType, listener);
    label.removeListener(eventType, listener);
  }

  @Override
  public Object getLayoutData() {
    return super.getLayoutData();
  }

  public void setSelection(boolean selected) {
    btn.setSelection(selected);
  }

  public boolean getSelection() {
    return btn.getSelection();
  }

  @Override
  public void addListener(int eventType, Listener listener) {
    super.addListener(eventType, listener);
    btn.addListener(eventType, listener);
    label.addListener(eventType, listener);
  }
}

Previous Topic:Detached view freeze until resized
Next Topic:Browser.getText returning incomplete/inaccurate page string.
Goto Forum:
  


Current Time: Fri Jul 25 23:18:26 EDT 2014

Powered by FUDForum. Page generated in 0.02398 seconds