本文介绍了我可以组合SWT GridLayout和FillLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RCP / SWT应用程序,我正在尝试用现有的复合材料构建一个视图。一个是FillLayout复合,另一个是GridLayout。

I have an RCP/SWT application in which I'm trying to construct a view out of existing composites. One is a FillLayout composite, the other uses GridLayout.

我想最终得到一个视图,其中GridLayout复合排列在左边的FillLayout复合(想想垂直横幅),大约是整个视图宽度的10%,现有的FillLayout复合包含其他90%。

I'd to like to end up with a view in which the GridLayout composite is lined up to the left of the FillLayout composite (think vertical banner) and is about 10 percent the width of the entire view, with the existing FillLayout composite comprising the other 90 percent.

我不确定如果在SWT中可以组合布局,但我正在考虑像两个列的GridLayout。第一列包含GridLayout小部件,第二列包含FillLayout组合。这可以在SWT中完成吗?如果是这样,这看起来像代码一样?

I'm not sure if it is possible in SWT to combine layouts, but I'm thinking something like a GridLayout with two columns. Column one would contain the GridLayout widget and column two would contain the FillLayout composite. Can this be done in SWT? If so, what does this look like code-wise?

谢谢 -

推荐答案

开始将 FormLayout 设置为外部合成。在其中放置另外两个复合材料,设置 FormData 信息,以便根据需要定位它们。然后设置这两个复合的布局(网格和填充,如你所说)。

Start setting a FormLayout to your outer composite. Place two other composites inside it, setting their FormData information to position them as you please. Then set those two composite's layouts (Grid and Fill, as you said).

这里有一些代码可以启动。在显示它产生的东西之后有一个图像。
您也可以查看Eclipse的 SWT Layouts 视图。

Here's some code to start. There's an image after it showing what it produces.You might also check out Eclipse's SWT Layouts view.

Shell shell = new Shell();

FillLayout fillLayout = new FillLayout();
fillLayout.marginHeight = 5;
fillLayout.marginWidth = 5;
shell.setLayout( fillLayout );

Composite outer = new Composite( shell, SWT.BORDER );
outer.setBackground( new Color( null, 207, 255, 206 ) ); // Green

FormLayout formLayout = new FormLayout();
formLayout.marginHeight = 5;
formLayout.marginWidth = 5;
formLayout.spacing = 5;
outer.setLayout( formLayout );

Composite innerLeft = new Composite( outer, SWT.BORDER );
innerLeft.setLayout( new GridLayout() );
innerLeft.setBackground( new Color( null, 232, 223, 255 ) ); // Blue

FormData fData = new FormData();
fData.top = new FormAttachment( 0 );
fData.left = new FormAttachment( 0 );
fData.right = new FormAttachment( 10 ); // Locks on 10% of the view
fData.bottom = new FormAttachment( 100 );
innerLeft.setLayoutData( fData );

Composite innerRight = new Composite( outer, SWT.BORDER );
innerRight.setLayout( fillLayout );
innerRight.setBackground( new Color( null, 255, 235, 223 ) ); // Orange

fData = new FormData();
fData.top = new FormAttachment( 0 );
fData.left = new FormAttachment( innerLeft );
fData.right = new FormAttachment( 100 );
fData.bottom = new FormAttachment( 100 );
innerRight.setLayoutData( fData );

shell.open();

这篇关于我可以组合SWT GridLayout和FillLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 22:27