如何更改ScrolledComposite的水平滚动增量?

时间:2023-01-20 17:13:01

I have an application that displays a ScrolledComposite. Users are complaining that the horizontal scrolling increment is too fine, i.e. each click on the horizontal scroll arrow currently moves the bar one pixel at a time. They want individual clicks to cause greater horizontal movement. Could someone explain how I could implement this? A snippet of the code follows:

我有一个显示ScrolledComposite的应用程序。用户抱怨水平滚动增量太细,即水平滚动箭头上的每次点击当前一次将条移动一个像素。他们希望单击会导致更大的水平移动。有人可以解释我如何实现这个?代码片段如下:

ScrolledComposite myScrolledComposite = new ScrolledComposite(parent, 
        SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

if ( myScrolledComposite == null) {
    throw new NullPointerException("ScenePreView.java:  " + 
            "Method createPartControl()  " + 
            "ScrolledComposite myScrolledComposite == null."); 
}

Composite myComposite = new Composite(myScrolledComposite, SWT.NONE);

if ( myComposite == null) {
    throw new NullPointerException("ScenePreView.java:  " + 
            "Method createPartControl()  " + 
            "Composite myComposite == null."); 
}

myScrolledComposite.setContent(myComposite);

4 个解决方案

#1


This should work pretty well and provide usable defaults. It should update automatically when the control inside the ScrolledComposite is resized.

这应该可以很好地工作并提供可用的默认值。当ScrolledComposite中的控件调整大小时,它应该自动更新。

myComposite.addControlListener( new ControlAdapter() {
    @Override
    public void controlResized( ControlEvent e ) {
        ScrollBar sbX = scrolledComposite.getHorizontalBar();
        if ( sbX != null ) {
            sbX.setPageIncrement( sbX.getThumb() );
            sbX.setIncrement( Math.max( 1, sbX.getThumb() / 5 ) );
        }
    }
});

#2


Get the scrollbar from the composite and set it's increment.

从组合中获取滚动条并设置它的增量。

myScrolledComposite.getVerticalBar().setIncrement(10);

#3


Use the setIncrement() method of the SWT Scrollbar class. This lets you modify the amount by which the scroll region moves when the arrow buttons are pressed. See API Reference for SWT

使用SWT Scrollbar类的setIncrement()方法。这使您可以修改按下箭头按钮时滚动区域移动的量。请参阅SWT的API参考

#4


I know it's more than you asked for, but I highly recommend checking out the SWT animation toolkit which has an implementation of smooth scrolling. It will make your application way cooler.

我知道它比你要求的要多,但我强烈建议你看一下SWT动画工具包,它有一个平滑滚动的实现。它将使您的应用程序更酷。

You can check it out and see the sources - it's a good example (yet, a bit advanced) of how to play with the scrolling.

您可以查看它并查看源代码 - 这是一个很好的例子(但有点高级)如何使用滚动。

#1


This should work pretty well and provide usable defaults. It should update automatically when the control inside the ScrolledComposite is resized.

这应该可以很好地工作并提供可用的默认值。当ScrolledComposite中的控件调整大小时,它应该自动更新。

myComposite.addControlListener( new ControlAdapter() {
    @Override
    public void controlResized( ControlEvent e ) {
        ScrollBar sbX = scrolledComposite.getHorizontalBar();
        if ( sbX != null ) {
            sbX.setPageIncrement( sbX.getThumb() );
            sbX.setIncrement( Math.max( 1, sbX.getThumb() / 5 ) );
        }
    }
});

#2


Get the scrollbar from the composite and set it's increment.

从组合中获取滚动条并设置它的增量。

myScrolledComposite.getVerticalBar().setIncrement(10);

#3


Use the setIncrement() method of the SWT Scrollbar class. This lets you modify the amount by which the scroll region moves when the arrow buttons are pressed. See API Reference for SWT

使用SWT Scrollbar类的setIncrement()方法。这使您可以修改按下箭头按钮时滚动区域移动的量。请参阅SWT的API参考

#4


I know it's more than you asked for, but I highly recommend checking out the SWT animation toolkit which has an implementation of smooth scrolling. It will make your application way cooler.

我知道它比你要求的要多,但我强烈建议你看一下SWT动画工具包,它有一个平滑滚动的实现。它将使您的应用程序更酷。

You can check it out and see the sources - it's a good example (yet, a bit advanced) of how to play with the scrolling.

您可以查看它并查看源代码 - 这是一个很好的例子(但有点高级)如何使用滚动。