How to align two composites in a parent composite

2019-07-18 10:30发布

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.

3条回答
Animai°情兽
2楼-- · 2019-07-18 10:37

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.

查看更多
Anthone
3楼-- · 2019-07-18 10:42

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.

查看更多
Emotional °昔
4楼-- · 2019-07-18 11:03

I suggest you to try WidowBuilder Pro This will help you to build HMI rapidly

查看更多
登录 后发表回答