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

Bug 150418

Summary: ScrollBar figure get created although the Pane set the scroll bar visibilty to NEVER
Product: [Tools] GEF Reporter: Mohammed Mostafa <mmostafa>
Component: GEF-Legacy Draw2dAssignee: gef-inbox <gef-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Mohammed Mostafa CLA 2006-07-12 13:28:47 EDT
The fact that the ScrollPaneLayout#layout method do 
ScrollBar hBar = scrollpane.getHorizontalScrollBar(),
		      vBar = scrollpane.getVerticalScrollBar();

in line 86 and 87, means that the Vscroll bar and the Horizontal scroll bar wil be created regardless of the fact that the HorizontalScrollBarVisibility or the VerticalScrollBarVisibility might be set to NEVER

If the implementation of this method is changed to look like this 


ScrollPane scrollpane = (ScrollPane) parent;
		Rectangle clientArea = parent.getClientArea();
		int bottom = 0;
		int right  = 0 ;

		int hVis = scrollpane.getHorizontalScrollBarVisibility(),
		vVis = scrollpane.getVerticalScrollBarVisibility();
		
		
		Viewport viewport = scrollpane.getViewport();
		Dimension available = clientArea.getSize();
		Dimension preferred = viewport.getPreferredSize(available.width, available.height).getCopy();
		boolean none = available.contains(preferred);
		boolean both =
			!none
				&& vVis != NEVER
				&& hVis != NEVER
				&& preferred.contains(available);
		boolean showV = both || preferred.height > available.height;
		boolean showH = both || preferred.width > available.width;
		//Adjust for visibility override flags
		showV = !(vVis == NEVER) && (showV || vVis == ALWAYS);
		showH = !(hVis == NEVER) && (showH || hVis == ALWAYS);
		Rectangle bounds, viewportArea = clientArea;
		int hPad = 0;
		int vPad = 0;
		ScrollBar vBar = null;
		ScrollBar hBar = null;
		
		if (hVis!=NEVER)
			hBar = scrollpane.getHorizontalScrollBar();
		if (vVis!=NEVER)
			vBar = scrollpane.getVerticalScrollBar();
				
		if (showH){
			bottom = hBar.getPreferredSize(clientArea.width, clientArea.height).height;
			hPad = hBar.getSize().height;
		}
		
		if (showV){
			right =	vBar.getPreferredSize(clientArea.width, clientArea.height).width;
			vPad = vBar.getSize().width;
		}
		
		if (showV) {
			bounds =
				new Rectangle(
					viewportArea.right() - right,
					viewportArea.y,
					right,
					viewportArea.height - hPad);
			vBar.setBounds(bounds);
		}
		if (showH) {
			bounds =
				new Rectangle(
					viewportArea.x,
					viewportArea.bottom() - bottom,
					viewportArea.width - vPad,
					bottom);
			hBar.setBounds(bounds);
		}
		if (vBar!=null)
			vBar.setVisible(showV);
		if (hBar!=null)
			hBar.setVisible(showH);
		viewport.setBounds(viewportArea);

Then the Scroll bars with Visibility set to never will not be created
Comment 1 Randy Hudson CLA 2006-07-20 15:57:33 EDT
The change is to avoid calling a method so that lazy creation doesn't occur? The change sounds fine to me, but I don't expect huge savings in memory usage.

Subclasses have access to the protected fields directly, so some clients might expect the fields to not be NULL, perhaps when painting or something. Changing this in the maintenance stream might break working client code.
Comment 2 Alexander Nyßen CLA 2011-10-12 16:14:51 EDT
I think it would be cleaner to not return a scrollbar within scrollpane if there is no scrollbar. However, this would be an API-incompatible change. Due to this and the fact that there are protected fields involved (as Randy pointed out), resolving as WORKSFORME.