Reputation: 1138
I work on an Eclipse plug-in and at a moment in time a pop-up is shown. Inside the pop-up dialog box, I want to create an area where I have a label on the left and two buttons alligned right.
public void createBottom(Composite parent) {
Composite composite = new Composite(parent, SWT.FILL | SWT.WRAP | SWT.BORDER);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
composite.setLayoutData(gridData);
composite.setLayout(new GridLayout(3, false));
addLabel(composite);
addButton1(composite);
addButton2(composite);
}
Currently the result looks like this:
While I'm expecting something more like this:
How can I possibly align the Label
on the left and the two buttons on the right?
Upvotes: 0
Views: 1510
Reputation: 111142
First SWT.FILL
and SWT.WRAP
are not valid styles for Composite
. The Javadoc for the control specifies which styles you can use.
Use something like:
Composite composite = new Composite(parent, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false);
composite.setLayoutData(gridData);
composite.setLayout(new GridLayout(3, false));
Label label = new Label(composite, SWT.BEGINNING);
label.setText("Test");
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Button but1 = new Button(composite, SWT.PUSH);
but1.setText("OK");
but1.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
Button but2 = new Button(composite, SWT.PUSH);
but2.setText("Close");
but2.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
The layout data for the label grabs the extra space in the composite, and the buttons have end alignment.
Upvotes: 2