문제

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?

도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top