How to align two composites in a parent composite without using widthHint and heightHint

℡╲_俬逩灬. 提交于 2019-12-11 02:43:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!