I am trying to use BooleanFieldEditor instead of Button with style SWT.CHECK. And I am getting the problem with layout of the checkbox.
The significant part of my previous code is:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button checkBox = new Button(projectGroup, SWT.CHECK);
checkBox.setText(Messages.getString("WizardNewProjectCreationPage.createEmptyProject")); //$NON-NLS-1$
checkBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
Button button = (Button) event.getSource();
shouldEmptyProjectBeCreated = button.getSelection();
}
});
It gives me this result:
In this case the checkbox has a small indent at the top and the left side.
The significant part of my current code is:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(100, 0, 100, 0).spacing(100, 100).applyTo(projectGroup);
BooleanFieldEditor emptyProjectCheckbox = new BooleanFieldEditor("createEmptyProject",
Messages.getString("WizardNewProjectCreationPage.createEmptyProject"), projectGroup);
// GridDataFactory.defaultsFor(projectGroup).grab(true, false).span(2, 1).applyTo(projectGroup);
// emptyProjectCheckbox.fillIntoGrid(projectGroup, 1);
createEmptyProject = emptyProjectCheckbox.getBooleanValue();
Whatever values I set into extendedMargins() and spacing() methods, the result is the same - checkbox is located strictly at the level of the upper frame:
As you can see, in this case indents are smaller than on the first picture. I want to make the same indents as on the first image and want to understand, how to manage the location of BooleanFieldEditor's checkbox relatively to another elements.
Using second composite solves the problem:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(5, 0, 5, 0).applyTo(projectGroup);
//intermediate composite, which needs to work around the problem with layout of checkbox of BooleanFieldEditor
Composite intermediateComposite = new Composite(projectGroup, SWT.NONE);
BooleanFieldEditor emptyProjectCheckbox = new BooleanFieldEditor("createEmptyProject",
Messages.getString("WizardNewProjectCreationPage.createEmptyProject"), intermediateComposite);
createEmptyProject = emptyProjectCheckbox.getBooleanValue();