在下面的代码中,scroll
设置在Group
之外,如何将其置于Group
之内?
protected Control createDialogArea(Composite parent) {
composite = (Composite) super.createDialogArea(parent);
ScrolledComposite scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
innerComposite.setLayout(new GridLayout());
grpModelProperties1 = new Group(innerComposite, SWT.SHADOW_IN);
grpModelProperties1.setLayout(new GridLayout());
grpModelProperties1.setText("Test Model");
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 200;
grpModelProperties1.setLayoutData(data1);
scrolledComposite.setContent(innerComposite);
scrolledComposite.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
drawWitness(model);
return composite;
}
private void drawWitness(IWitnessModel witness) {
IWitnessVisualizer visualizer = WitnessUtil.getWitnessVisualizer(witness);
for (Control ctrl : grpModelProperties1.getChildren()) {
ctrl.dispose();
}
visualizer.render(grpModelProperties1);
grpModelProperties1.pack();
}
答案 0 :(得分:1)
目前,您正在Group
内innerComposite
内创建ScrolledComposite
。
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
...
grpModelProperties1 = new Group(innerComposite, SWT.SHADOW_IN);
如果您希望滚动显示在Group
内,只需在ScrolledComposite
上创建Group
:
protected Control createDialogArea(Composite parent) {
composite = (Composite) super.createDialogArea(parent);
// Create the Group on the top level Composite
grpModelProperties1 = new Group(composite, SWT.SHADOW_IN);
GridData data1 = new GridData(SWT.FILL, SWT.TOP, true, false);
data1.heightHint = 200;
grpModelProperties1.setLayoutData(data1);
grpModelProperties1.setLayout(new GridLayout());
grpModelProperties1.setText("Test Model");
// Within the Group, create the ScrolledComposite
ScrolledComposite scrolledComposite = new ScrolledComposite(grpModelProperties1, SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
// Create the scrolled content (the inner composite)
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
innerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
innerComposite.setLayout(new GridLayout());
// Some misc. data to test the scrolling
final Label label = new Label(innerComposite, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
label.setText("a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr");
scrolledComposite.setContent(innerComposite);
scrolledComposite.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return composite;
}