Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new button to buttons bar of JFace dialog

I need a button to be constantly placed at the bottom left corner of my JFace dialog even on re size of dialog.

I have overridden the createButtonsForButtonBar()

protected void createButtonsForButtonBar(Composite parent)
{
    sampleButton = createButton(parent, IDialogConstants.NO_ID, "Sample", true);
    createButton(parent, IDialogConstants.OK_ID,"OK", false);
    createButton(parent, IDialogConstants.CANCEL_ID,"Close", false);
}

I want the sample button to be placed at the bottom left, followed by spaces and then ok,cancel.

How do i achieve this?

like image 620
user1168608 Avatar asked Jan 28 '14 07:01

user1168608


1 Answers

This is the way the Eclipse About dialog does this:

protected void createButtonsForButtonBar(Composite parent)
{
  // Change parent layout data to fill the whole bar
  parent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

  sampleButton = createButton(parent, IDialogConstants.NO_ID, "Sample", true);

  // Create a spacer label
  Label spacer = new Label(parent, SWT.NONE);
  spacer.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

  // Update layout of the parent composite to count the spacer
  GridLayout layout = (GridLayout)parent.getLayout();
  layout.numColumns++;
  layout.makeColumnsEqualWidth = false;

  createButton(parent, IDialogConstants.OK_ID,"OK", false);
  createButton(parent, IDialogConstants.CANCEL_ID,"Close", false);
}
like image 172
greg-449 Avatar answered Sep 21 '22 15:09

greg-449