我想知道是否可以使用鼠标滚轮滚动ScrolledComposite
。默认情况下,它不起作用。
最佳答案
显然,有必要为您的组合创建鼠标滚轮监听器。您可以使用以下内容作为基础:
scrolledComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
GridData scrollGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
scrolledComposite.setLayoutData(scrollGridData);
layout = new GridLayout();
scrolledComposite.setLayout(layout);
compositeWrapper = new Composite(scrolledComposite);
compositeWrapper.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
compositeWrapper.setLayout(layout);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
int wheelCount = event.count;
wheelCount = (int) Math.ceil(wheelCount / 3.0f);
while (wheelCount < 0) {
scrolledComposite.getVerticalBar().setIncrement(4);
wheelCount++;
}
while (wheelCount > 0) {
scrolledComposite.getVerticalBar().setIncrement(-4);
wheelCount--;
}
}
});