Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ScrolledComposite scrolling in tiny steps if I click in the scroll bar(Question around page-scrolling in a ScrolledComposite)
ScrolledComposite scrolling in tiny steps if I click in the scroll bar [message #521960] Fri, 19 March 2010 13:19 Go to next message
Dominik Stadler is currently offline Dominik StadlerFriend
Messages: 3
Registered: July 2009
Junior Member
Hi,

I am trying to use ScrolledComposite with SWT/Eclipse 3.5.2 and was trying out the snippets at http://www.eclipse.org/swt/snippets/#scrolledcomposite

What I found is that each of the snippets shows a strange scrolling behavior. If I click into the scrollbar region, I usually expect the area to scroll by one page. However what happens with ScrolledComposite is that it only scrolls a bit, much less than a page.

I found Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=39934 which handles this problem, but there no progress since 2004.

I also found http://stackoverflow.com/questions/858591/how-do-you-change- a-scrolledcomposites-horizontal-scroll-increment, which proposes a workaround, however this does not work for me.

What do I need to make this work?

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;

public class Snippet5_WithPageScroll {

public static void main (String [] args) 
{
    Display display = new Display ();
    Shell shell = new Shell (display);
    shell.setLayout(new FillLayout());

    // this button is always 400 x 400. Scrollbars appear if the window is resized to be
    // too small to show part of the button
    final ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    Button b1 = new Button(c1, SWT.PUSH);
    b1.setText("fixed size button");
    b1.setSize(400, 400);
    c1.setContent(b1);

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

    shell.setSize(600, 300);
    shell.open ();
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
    display.dispose ();
}

}


Thanks... Dominik.
Re: ScrolledComposite scrolling in tiny steps if I click in the scroll bar [message #522479 is a reply to message #521960] Mon, 22 March 2010 13:28 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
It looks like the ControlListener being added should be more like the
following (?):

c1.addControlListener( new ControlAdapter() {
public void controlResized( ControlEvent e ) {
ScrollBar sbY = c1.getVerticalBar();
if ( sbY != null ) {
sbY.setPageIncrement(c1.getSize().y);
}
}
});

HTH,
Grant


"Dominik Stadler" <dominik.stadler@gmx.at> wrote in message
news:hnvtl1$vrf$1@build.eclipse.org...
> Hi,
>
> I am trying to use ScrolledComposite with SWT/Eclipse 3.5.2 and was trying
out the snippets at http://www.eclipse.org/swt/snippets/#scrolledcomposite
>
> What I found is that each of the snippets shows a strange scrolling
behavior. If I click into the scrollbar region, I usually expect the area to
scroll by one page. However what happens with ScrolledComposite is that it
only scrolls a bit, much less than a page.
>
> I found Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=39934 which
handles this problem, but there no progress since 2004.
>
> I also found
http://stackoverflow.com/questions/858591/how-do-you-change- a-scrolledcomposites-horizontal-scroll-increment,
which proposes a workaround, however this does not work for me.
>
> What do I need to make this work?
>
>
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.layout.*;
> import org.eclipse.swt.custom.*;
> import org.eclipse.swt.events.ControlAdapter;
> import org.eclipse.swt.events.ControlEvent;
>
> public class Snippet5_WithPageScroll {
>
> public static void main (String [] args)
> {
> Display display = new Display ();
> Shell shell = new Shell (display);
> shell.setLayout(new FillLayout());
>
> // this button is always 400 x 400. Scrollbars appear if the window is
resized to be
> // too small to show part of the button
> final ScrolledComposite c1 = new ScrolledComposite(shell, SWT.BORDER |
SWT.H_SCROLL | SWT.V_SCROLL);
> Button b1 = new Button(c1, SWT.PUSH);
> b1.setText("fixed size button");
> b1.setSize(400, 400);
> c1.setContent(b1);
>
> shell.addControlListener( new ControlAdapter() {
> @Override
> public void controlResized( ControlEvent e ) {
> ScrollBar sbX = c1.getHorizontalBar();
> if ( sbX != null ) {
> sbX.setPageIncrement( sbX.getThumb() );
> sbX.setIncrement( Math.max( 1, sbX.getThumb() / 5 ) );
> }
> }
> });
>
> shell.setSize(600, 300);
> shell.open ();
> while (!shell.isDisposed ()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>
> }
>
>
> Thanks... Dominik.
>
Re: ScrolledComposite scrolling in tiny steps if I click in the scroll bar [message #522831 is a reply to message #522479] Wed, 24 March 2010 07:02 Go to previous message
Dominik Stadler is currently offline Dominik StadlerFriend
Messages: 3
Registered: July 2009
Junior Member
Thanks, that pointed me in the right direction, I now call the following in the ControlListener to set this for both horizontal and vertical scrollbar and also for step scrolling, SCROLL_FACTOR is 1 at the moment, but can be adjusted to get more than one page scrolling:

	public static void setScrollbarIncrement(final ScrolledComposite scrolledComposite) {
		ScrollBar sbX = scrolledComposite.getHorizontalBar();
	    if ( sbX != null ) {
	        sbX.setPageIncrement( Math.round(scrolledComposite.getSize().y*SCROLL_FACTOR) );
	        sbX.setIncrement( Math.max( 1, scrolledComposite.getSize().y / 5 ) );
	    }

	    ScrollBar sbY = scrolledComposite.getVerticalBar();
	    if ( sbY != null ) {
	        sbY.setPageIncrement( Math.round(scrolledComposite.getSize().y*SCROLL_FACTOR) );
	        sbY.setIncrement( Math.max( 1, scrolledComposite.getSize().y / 5 ) );
	    }
	}


Thanks... Dominik
Previous Topic:Key Binding problem
Next Topic:Strange behavior of gc.setForeground() and a table in Cocoa SWT
Goto Forum:
  


Current Time: Wed Dec 04 15:42:04 GMT 2024

Powered by FUDForum. Page generated in 0.03348 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top