问题
I want two composites (one below the other) inside a parent component.
This is how my code looks like:
Composite composite = (Composite) super.createDialogArea(parent);
Composite rowComposite = new Composite(composite, SWT.NONE);
rowComposite.setLayout(new GridLayout(2, false));
GridData gd1 = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gd1.widthHint = 760;
gd1.heightHint = 240;
rowComposite.setLayoutData(gd1);
Composite columnComposite = new Composite(composite, SWT.NONE);
columnComposite .setLayout(new GridLayout(2, false));
GridData gd2 = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gd2.widthHint = 760;
gd2.heightHint = 240;
columnComposite .setLayoutData(gd1);
Here, I'm using widthHint
and heightHint
which is not recommended as the whole layout will be ruined when the user decides to change the system font or resolution.
How do i achieve the same without using widthHint
and heightHint
.
回答1:
Removed the widthHint and heightHint from both composites and updated grid data as:
new GridData(SWT.FILL, SWT.FILL, true, true);
The GridLayout has taken care of width and height.
回答2:
composite.setLayout(new GridLayout(1, true));
Set layout of parent to GridLayout, which the first parameter is the number of columns and the second is whether or not the columns will have equal width.
回答3:
I suggest you to try WidowBuilder Pro This will help you to build HMI rapidly
来源:https://stackoverflow.com/questions/20742107/how-to-align-two-composites-in-a-parent-composite-without-using-widthhint-and-he