我正在为eclipse开发一个带有视图的插件,我需要使这个视图可滚动。我发现了如何使其可滚动,但复合材料出现在视图的右侧。如何填写所有视图?
我的代码:
public class Comp2 extends Composite {
public Comp2(Composite parent, int style) {
super(parent, SWT.NONE);
final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setLayout(new FillLayout());
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
final Composite subContainer = new Composite(sc, SWT.NONE);
Button btnNewButton = new Button(subContainer, SWT.NONE);
btnNewButton.setBounds(75, 99, 90, 30);
btnNewButton.setText("New Button");
Button btnNewButton_1 = new Button(subContainer, SWT.NONE);
btnNewButton_1.setBounds(357, 398, 90, 30);
btnNewButton_1.setText("New Button");
sc.setContent(subContainer);
sc.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = sc.getClientArea();
sc.setMinSize(subContainer
.computeSize(r.width, SWT.DEFAULT));
}
});
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
答案 0 :(得分:1)
由于您正在扩展Composite
,因此复合材料正在将其正常主体添加到父级。然后,您将ScrolledComposite
添加到父级,使其与第一个复合材料并排放置。
您可以通过更改其父级ScrollComposite
将Composite
置于super(parent, SWT.NONE);
// This composite needs a layout
setLayout(new FillLayout());
// Parent of the ScrolledComposite is this Composite
ScrolledComposite sc = new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL);
内:
semicolon, pipe, redirection and ampersand