How do you change A ScrolledComposite Horizontal Scroll Increment?

I have an application that displays a ScrolledComposite. Users complain that the horizontal scroll increment is too thin, meaning that each click on the horizontal scroll arrow currently moves the panel one pixel at a time. They want individual clicks to cause more horizontal movement. Can anyone explain how I can implement this? Below is the code snippet:

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


a source to share


4 answers


This should work very well and ensure that the default values ​​are used. It should update automatically when the control inside the ScrolledComposite changes.



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

      

+3


a source


Get a scrollbar from a composite set and set its increment.



myScrolledComposite.getVerticalBar () setIncrement (10) ;.

+2


a source


Use the setIncrement () method of the SWT Scrollbar class. This allows you to change the amount of movement of the scroll area when the arrow buttons are pressed. See API link for SWT

0


a source


I know this more than you asked, but I highly recommend checking out the SWT animation toolkit that has a smooth scrolling implementation. This will make your application look cooler.

You can check it out and see the sources - this is a good example (a little more advanced) of how to play with scrolling.

0


a source







All Articles