Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 376843

Summary: [ScrolledComposite] ScrollBar#setSelection doesn't work anymore
Product: [RT] RAP Reporter: Arian Storch <storch>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: ivan
Version: 1.5   
Target Milestone: 1.5 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Arian Storch CLA 2012-04-16 03:51:46 EDT
Build Identifier: 

Take a ScrollBar from a ScrolledComposite and use setSelection to adjust it. Nothing happens though minimum and maximum are correctly set. 

It already worked in an earlier Version.

Current Version: RAP 1.5M6

Code Snippet:
--
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
		
Composite cmp = new Composite(sc, SWT.NONE);
cmp.setLayout(new FillLayout());
		
Label lbl = new Label(cmp, SWT.NONE);
lbl.setBackground(Graphics.getColor(0, 255, 0));
		
cmp.setSize(1024, 800);
		
sc.setContent(cmp);
		
sc.setMinSize(cmp.getSize());
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
		
ScrollBar vBar = sc.getVerticalBar();
ScrollBar hBar = sc.getHorizontalBar();
		
sc.layout(true, true);
sc.pack();
		
System.out.println(vBar.getMinimum()+" "+vBar.getMaximum());
		
vBar.setSelection(100);

Reproducible: Always
Comment 1 Ivan Furnadjiev CLA 2012-04-16 05:56:28 EDT
Arian, just checked your snippet against SWT and the ScrolledComposite content location (ScrolledComposite vertical scrollbar position) is not set if you call ScrollBar#setSelection. Just add a sysout after vBar.setSelection( 100 ); to get the selection and you will get 0:
..
vBar.setSelection( 100 );
System.out.println( cmp.getLocation() );
System.out.println( vBar.getSelection() );
..
Even if it worked before I think that the bug is invalid. Please reopen if you disagree.
Comment 2 Ivan Furnadjiev CLA 2012-04-16 06:02:55 EDT
Just a note: If you want to scroll the ScrolledComposite programmatically use ScrolledComposite#setOrigin.
Comment 3 Arian Storch CLA 2012-04-16 15:48:58 EDT
Hi Ivan,

thanks for your investigation!

For RAP ScrolledComposite#setOrigin is working. But for "native" SWT ScrollBar#setSelection works too.

On a native platform both leads to nearly the same behavior. I've just tested it with Eclipse Version 3.7.0. Unfortunately the behavior for RAP isn't the same. As described above ScrollBar#setSelection doesn't work anymore.

Note: My first code snipped included an error. So I'm posting my test code again (for native SWT):
--
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
		
Composite cmp = new Composite(sc, SWT.BORDER);
cmp.setLayout(new GridLayout( 1, false));
		
Label lbl = new Label(cmp, SWT.NONE);
lbl.setBackground(new Color(Display.getCurrent(), 0, 255, 0));
lbl.setText("XXX");
	
cmp.setSize(1600, 2400);
		
sc.setContent(cmp);
		
sc.setMinSize(1024,978);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setAlwaysShowScrollBars(true);
		
ScrollBar vBar = sc.getVerticalBar();
ScrollBar hBar = sc.getHorizontalBar();
		
//sc.setOrigin(100,100);  //WORKS
		
vBar.setSelection(100); //BUT THIS ALSO
hBar.setSelection(100);
Comment 4 Arian Storch CLA 2012-04-16 15:49:36 EDT
I've just tested my snipped against RAP 1.4. Here it works fine and as expected!
Comment 5 Ivan Furnadjiev CLA 2012-04-16 16:38:29 EDT
Fixed in ScrolledCompositeLCA by getting the origin form the scrollbars selection (as it was in v1.4).