我正在尝试从TreeViewer的数据中水平填充复合,但没有成功。如果您有任何建议,我会非常感激。
这是我正在使用的代码:
private Composite composite;
private ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
composite = new Composite(scrolledComposite, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
composite.setLayout(createNoMarginLayout(1, false));
scrolledComposite.setContent(composite);
compositeNdal = new Composite(composite, SWT.NONE);
compositeNdal.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
compositeNdal.setLayout(createNoMarginLayout(1, true));
compositeNdal.setVisible(true);
treeViewerNdalEditor = new TreeViewer(compositeNdal,SWT.BORDER|SWT.FILL);
/* (computing the tree part goes here) */
public static GridLayout createNoMarginLayout(int numColumns, boolean makeColumnsEqualWidth) {
GridLayout layout = new GridLayout(numColumns, makeColumnsEqualWidth);
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
layout.marginTop = 0;
layout.marginBottom = 0;
layout.marginLeft = 0;
layout.marginRight = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
return layout;
}
答案 0 :(得分:0)
您必须在树上设置布局数据,以告知父复合布局如何处理树:
treeViewerNdalEditor.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));