How to add a new button to buttons bar of JFace dialog
dialog, java, jface, swt
Solution
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);
}
Problem
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?