Bug 29381 - [ScrolledComposite] ScrolledComposite Flicker
Summary: [ScrolledComposite] ScrolledComposite Flicker
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Duong Nguyen CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-13 09:10 EST by Jason Agee CLA
Modified: 2020-11-10 08:14 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Agee CLA 2003-01-13 09:10:34 EST
Whenever a ScrolledComposite is displayed, there can be a flicker of the scroll 
bars. This flicker seems to occur as the components which will be displayed on 
the scrolled composite are being constructed. I have included a test case below. 
The flicker is not very pronounced in this test, but it can be seen. As the 
construction of the comp1, and comp2 interfaces becomes more complex, the 
flicker seems to get worse (at least on my real program it is worse than in the 
test case). Clicking on the list on the left, updates the interface on the 
right, at which point the flicker occurs. I am running XP @ 1.8 Ghz. Thanks.




Jason Agee






import org.eclipse.swt.widgets.*;


import org.eclipse.swt.custom.*;


import org.eclipse.swt.layout.*;


import org.eclipse.swt.*;


import org.eclipse.swt.events.*;






/**


 *


 * This will build an interface with a list on the left side of a SashForm and a


 * ScrolledComposite on the right side of the SashForm. Whenever the list is


 * selected, the interface on the right side is update to display new


 * components. When this happens, you can see a flicker of the scroll bars being


 * initially displayed on the ScrolledComposite. With this particular test, the


 * flicker is noticeable, but minor and not too much of a problem (though it


 * should probably still not happen), but as the interface constructed on the


 * right becomes more complex, the flicker becomes more pronounced.


 */


public class FlickerTest {


 private ScrolledComposite scrolledComposite;


 private SashForm sashForm;


 private Composite holdScroll;


 private Composite comp1;


 private Composite comp2;


 private List list;




 public FlickerTest (){


 //Create the main shell


  Shell shell = new Shell();


  shell.setLayout(new FillLayout());




  //setup the SashForm


  sashForm = new SashForm(shell, SWT.NONE);




  //Setup the list


  list = new List(sashForm, SWT.BORDER);


  list.addSelectionListener(new SelectionAdapter(){


   public void widgetSelected(SelectionEvent e){


    FlickerTest.this.handleSelection();


   }


  });


  list.add("Composite 1");


  list.add("Composite 2");




  //Setup the composite which will hold the data


  holdScroll = new Composite(sashForm, SWT.BORDER);


  FillLayout fl =new FillLayout();


  holdScroll.setLayout(fl);




     //Open the shell


  shell.open();


  Display display = shell.getDisplay();


  while (!shell.isDisposed()) {


   if(!display.readAndDispatch()) display.sleep();


  }




 }




 /**


  * When the list is selected, show the correct interface on the


  * scrolledComposite.


  */


 public void handleSelection(){


  if(list.getSelectionIndex() == 0){


   showComp1();


  }


  if(list.getSelectionIndex() == 1){


   showComp2();


  }


 }




 /**


  * Show the Composite 1 interface


  */


 public void showComp1(){


  disposeOpenComp();


  //setup the scrolledComposite


  scrolledComposite = new ScrolledComposite(holdScroll, SWT.H_SCROLL |


SWT.V_SCROLL);


  comp1 = new Composite(scrolledComposite, SWT.NONE);


  scrolledComposite.setContent(comp1);


  GridLayout gl = new GridLayout(2, false);


  comp1.setLayout(gl);


  Button b;


  for(int i = 0; i < 100; i++){


   b = new Button(comp1, SWT.BORDER);


   b.setText("Comp1 Button - " + i);


  }


  comp1.setSize(comp1.computeSize(SWT.DEFAULT, SWT.DEFAULT));


  holdScroll.layout();


 }




 /**


  * Show the Composite 2 interface


  */


 public void showComp2(){


  disposeOpenComp();


  //setup the scrolledComposite


  scrolledComposite = new ScrolledComposite(holdScroll, SWT.H_SCROLL |


SWT.V_SCROLL);


  comp2 = new Composite(scrolledComposite, SWT.NONE);


  scrolledComposite.setContent(comp2);


  GridLayout gl = new GridLayout(2, false);


  comp2.setLayout(gl);


  scrolledComposite.layout(true);


  Button b;


  for(int i = 0; i < 100; i++){


   b = new Button(comp2, SWT.BORDER);


   b.setText("Comp2 Button - " + i);


  }


  comp2.setSize(comp2.computeSize(SWT.DEFAULT, SWT.DEFAULT));


  holdScroll.layout();


 }




 /**


  * Close the open components.


  */


 public void disposeOpenComp(){


  if(comp1 != null){


   comp1.dispose();


   scrolledComposite.dispose();


   comp1=null;


   scrolledComposite = null;


  }


  if(comp2 != null){


   comp2.dispose();


   scrolledComposite.dispose();


   comp2=null;


   scrolledComposite = null;


  }


 }




 public static void main(String[] args){


  FlickerTest ft = new FlickerTest();


 }


}
Comment 1 Felipe Heidrich CLA 2003-01-13 10:36:00 EST
VI to advise
Comment 2 Steve Northover CLA 2003-01-13 15:31:47 EST
Asigning to VI to figure out if any more action is necessary.

Here is code that "works around" the problem.  This is what is going on.  The 
initial size of the ScrolledComposite is zero therefore the scroll bars are 
required.  When the FillLayout resizes the ScrolledComposite, Windows draws the 
scroll bars at their new location (ther are visible) before ScrolledComposite 
gets the resize callback which it uses to determine scroll bar visibility.  The 
work around hides the ScrolledComposite while all the resizing is happening.  
This doesn't cause extra flash because the widget tree is being destroyed and 
recreated anyway.

Destroying and recreating the ScrolledComposite should not be necessary.  You 
should be able to just set the new contents (that may flash too but shouldn't 
but we haven't tried it).

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

/**
 *
 * This will build an interface with a list on the left side of a SashForm and a
 * ScrolledComposite on the right side of the SashForm. Whenever the list is
 * selected, the interface on the right side is update to display new
 * components. When this happens, you can see a flicker of the scroll bars being
 * initially displayed on the ScrolledComposite. With this particular test, the
 * flicker is noticeable, but minor and not too much of a problem (though it
 * should probably still not happen), but as the interface constructed on the
 * right becomes more complex, the flicker becomes more pronounced.
 */

public class PR_29381 {
	private ScrolledComposite scrolledComposite;
	private SashForm sashForm;
	private Composite holdScroll;
	private Composite comp1;
	private Composite comp2;
	private List list;

	public PR_29381() {

		//Create the main shell

		Shell shell = new Shell();
		shell.setLayout(new FillLayout());

		//setup the SashForm
		sashForm = new SashForm(shell, SWT.NONE);

		//Setup the list
		list = new List(sashForm, SWT.BORDER);
		list.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				PR_29381.this.handleSelection();

			}

		});
		list.add("Composite 1");
		list.add("Composite 2");

		//Setup the composite which will hold the data
		holdScroll = new Composite(sashForm, SWT.BORDER);
		FillLayout fl = new FillLayout();
		holdScroll.setLayout(fl);

		//Open the shell
		shell.open();

		Display display = shell.getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	/**
	 * When the list is selected, show the correct interface on the
	 * scrolledComposite.
	 */

	public void handleSelection() {
		if (list.getSelectionIndex() == 0) {
			showComp1();
		}
		if (list.getSelectionIndex() == 1) {
			showComp2();
		}
	}

	/**
	 * Show the Composite 1 interface
	 */

	public void showComp1() {
		disposeOpenComp();

		//setup the scrolledComposite
		scrolledComposite =
			new ScrolledComposite(holdScroll, SWT.H_SCROLL | 
SWT.V_SCROLL);
		comp1 = new Composite(scrolledComposite, SWT.NONE);
		scrolledComposite.setContent(comp1);

		GridLayout gl = new GridLayout(2, false);
		comp1.setLayout(gl);
		Button b;
		for (int i = 0; i < 100; i++) {
			b = new Button(comp1, SWT.BORDER);
			b.setText("Comp1 Button - " + i);
		}
		//WORK ARPOUND - hide and show the scrolledComposite
		scrolledComposite.setVisible (false);
		comp1.setSize(comp1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		holdScroll.layout();
		scrolledComposite.setVisible (true);
	}

	/**
	 * Show the Composite 2 interface
	 */

	public void showComp2() {
		disposeOpenComp();

		//setup the scrolledComposite
		scrolledComposite =
			new ScrolledComposite(holdScroll, SWT.H_SCROLL | 
SWT.V_SCROLL);
		comp2 = new Composite(scrolledComposite, SWT.NONE);
		scrolledComposite.setContent(comp2);
		GridLayout gl = new GridLayout(2, false);
		comp2.setLayout(gl);
		Button b;
		for (int i = 0; i < 100; i++) {
			b = new Button(comp2, SWT.BORDER);
			b.setText("Comp2 Button - " + i);

		}
		//WORK ARPOUND - hide and show the scrolledComposite
		scrolledComposite.setVisible (false);
		comp2.setSize(comp2.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		holdScroll.layout();
		scrolledComposite.setVisible (true);
	}

	/**
	 * Close the open components.
	 */

	public void disposeOpenComp() {
		if (comp1 != null) {
			comp1.dispose();
			scrolledComposite.dispose();
			comp1 = null;
			scrolledComposite = null;
		}
		if (comp2 != null) {
			comp2.dispose();
			scrolledComposite.dispose();
			comp2 = null;
			scrolledComposite = null;
		}
	}

	public static void main(String[] args) {
		PR_29381 ft = new PR_29381();
	}

}
Comment 3 Eclipse Webmaster CLA 2019-09-06 15:35:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 4 Eugene Kiryakov CLA 2020-11-10 08:14:20 EST
I have bug similar to this. My swt structure is ScrolledComposite with content Composite(1) -> Composite(2) -> Composite(3) -> Label. When i set background color of composite(3) label flickers. Label is the last child of composite(3).
Eclipse 2020-06(4.16)