1

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 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);
1
  • Are you sure that the sensetivity is not set in the OS? Commented May 13, 2009 at 15:38

4 Answers 4

3

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

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 ) );
        }
    }
});
0
2

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

myScrolledComposite.getVerticalBar().setIncrement(10);

0
0

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

1
  • Thank You. I looked in the ScrolledComposite class, but didn't think to look in the Scrollbar class.
    – Dr. Faust
    Commented May 13, 2009 at 19:31
0

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.

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.