Reputation: 1021
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);
Upvotes: 1
Views: 2800
Reputation: 341
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 ) );
}
}
});
Upvotes: 3
Reputation: 9825
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.
Upvotes: 0
Reputation: 306
Get the scrollbar from the composite and set it's increment.
myScrolledComposite.getVerticalBar().setIncrement(10);
Upvotes: 2
Reputation: 2596
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
Upvotes: 0