Reputation: 206
I'm currently developing a custom plugin and I don't quite understand why a Composite element takes all the space even if other Composite elements are present.
My Handler for the execution of the plugin goes like this:
public class IwokGeneratorHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Shell shell = window.getShell();
ApplicationWindow win = new ApplicationWindow(shell) {
@Override
protected Control createContents(Composite parent) {
parent.setSize(800, 600);
//first panel
Composite composite = new Composite(parent, SWT.NONE);
//x, y, width, height
composite.setBounds(10, 10, 424, 70);
//second panel
Composite composite_1 = new Composite(parent, SWT.NONE);
composite_1.setBounds(10, 86, 424, 309);
//third panel
Composite composite_2 = new Composite(parent, SWT.NONE);
composite_2.setBounds(10, 407, 424, 42);
return parent;
}
};
win.open();
return null;
}
}
However, the first Composite takes all the space of the main Application window and the others cannot be seen, whatever the window size it is. I checked it multiple times.
Is there any property I'm missing to prevent elements to autifill?
Thank you in advance
Upvotes: 0
Views: 319
Reputation: 111142
ApplicationWindow
expects the createContents
method to return a single Composite
containing all the controls in the content (as do most other JFace window and dialog classes).
So something like:
protected Control createContents(final Composite parent) {
parent.setSize(800, 600);
// Main body composite
Composite body = new Composite(parent, SWT.NONE);
//first panel
Composite composite = new Composite(body, SWT.NONE);
//x, y, width, height
composite.setBounds(10, 10, 424, 70);
//second panel
Composite composite_1 = new Composite(body, SWT.NONE);
composite_1.setBounds(10, 86, 424, 309);
//third panel
Composite composite_2 = new Composite(body, SWT.NONE);
composite_2.setBounds(10, 407, 424, 42);
// Return the body
return body;
}
Note that your code is also returning parent
which is wrong - it must be the created composite.
Note: Although using setBounds
may look simple to start with it will cause problems if the code runs on different machines with different font sizes (or control sizes if you run on macOS/Linux/Windows). Using Layouts is strongly recommended.
Upvotes: 2