将滚动的内容放入组中 [英] Put scrolled content inside a Group
本文介绍了将滚动的内容放入组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,scroll
设置在 Group
之外,我如何将它放在 Group
内部?
In the below code, the scroll
set outside of the Group
, how can I put it inner the 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();
}
推荐答案
目前您正在 innerComposite
内创建 Group
,它位于 ScrolledComposite代码>.
Currently you're creating the Group
inside innerComposite
, which is inside the ScrolledComposite
.
Composite innerComposite = new Composite(scrolledComposite, SWT.NONE);
...
grpModelProperties1 = new Group(innerComposite, SWT.SHADOW_IN);
如果您希望滚动在 Group
内,只需在 Group
上创建 ScrolledComposite
:
If you want the scrolling to be inside the Group
, simply create the ScrolledComposite
on the Group
instead:
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;
}
这篇关于将滚动的内容放入组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文