Reputation: 107
I've created a custom JFace Wizard Dialog to add buttons. I found a way to change their position in the layout (like putting them between the cancel and the finish buttons) but it doesn't work when I try to put them between Previous and Next buttons.
Here is the code:
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button nextButton = getButton(IDialogConstants.NEXT_ID);
nextButton.setText(NEXT_LABEL);
Button backButton = getButton(IDialogConstants.BACK_ID);
backButton.setText(BACK_LABEL);
Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
cancelButton.setText(CANCEL_LABEL);
Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText(FINISH_LABEL);
rejectButton = super.createButton(parent, REJECT_ID, REJECT_LABEL, false);
rejectButton.moveAbove(nextButton);
setButtonLayoutData(rejectButton);
acceptButton = super.createButton(parent, ACCEPT_ID, ACCEPT_LABEL, false);
acceptButton.moveBelow(rejectButton);
setButtonLayoutData(acceptButton);
}
When I look at the wizard, I see that the space between Previous and Next buttons is thiner than the others. Look like they are binded together or something like that...
Is there another solution to change their position?
Thank you :)
Upvotes: 2
Views: 2386
Reputation: 107
After all, the solution was pretty easy =)
Back and Next buttons have their own parent composite inside the main composite :
private Composite createPreviousAndNextButtons(Composite parent) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Composite composite = new Composite(parent, SWT.NONE);
// create a layout with spacing and margins appropriate for the font
// size.
GridLayout layout = new GridLayout();
layout.numColumns = 0; // will be incremented by createButton
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
composite.setLayout(layout);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER
| GridData.VERTICAL_ALIGN_CENTER);
composite.setLayoutData(data);
composite.setFont(parent.getFont());
backButton = createButton(composite, IDialogConstants.BACK_ID,
IDialogConstants.BACK_LABEL, false);
nextButton = createButton(composite, IDialogConstants.NEXT_ID,
IDialogConstants.NEXT_LABEL, false);
return composite;
So, I changed the code of my overrided method to :
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
cancelButton.setText(CANCEL_LABEL);
Button finishButton = getButton(IDialogConstants.FINISH_ID);
finishButton.setText(FINISH_LABEL);
rejectButton = super.createButton(parent, REJECT_ID, REJECT_LABEL, false);
setButtonLayoutData(rejectButton);
acceptButton = super.createButton(parent, ACCEPT_ID, ACCEPT_LABEL, false);
acceptButton.moveBelow(rejectButton);
setButtonLayoutData(acceptButton);
if (super.getWizard().needsPreviousAndNextButtons()) {
Button nextButton = getButton(IDialogConstants.NEXT_ID);
nextButton.setText(NEXT_LABEL);
Button backButton = getButton(IDialogConstants.BACK_ID);
backButton.setText(BACK_LABEL);
// change composite parent of back and next buttons.
nextButton.setParent(parent);
backButton.setParent(parent);
((GridLayout) parent.getLayout()).numColumns = ((GridLayout) parent.getLayout()).numColumns + 2;
// defines buttons'order
finishButton.moveBelow(null);
cancelButton.moveAbove(finishButton);
nextButton.moveAbove(cancelButton);
acceptButton.moveAbove(nextButton);
rejectButton.moveAbove(acceptButton);
backButton.moveAbove(rejectButton);
}
}
=)
Upvotes: 3