I am implementing a Gantt component for SWT and it redraws a bit (e.g. 200 ms for the entire visible part of the chart).
Now when I scroll, I just redraw what is needed regarding the cropping rectangle. This makes the application really bad when I scroll quickly, because then the still visible part after scrolling seems to move the OS first, and when I finish drawing the rest (the part that became visible during scrolling), a new scroll step starts immediately by moving half of my chart to the right and letting me repaint the other half. It looks like my chart flickers in the middle while scrolling.
It doesnβt look very good. Is there any way around this? Is this question understandable?
EDIT : here is a small test program that shows exactly the described behavior. To run it, you only need a SWT in the classpath.
package de.ikoffice.gui; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class SlowRepaintProblem { public Color[] colors = new Color[501]; public SlowRepaintProblem() { Display display = Display.getDefault(); for( int i=0; i<=500; i++ ) { int r = ( i * 10 ) % 256; int g = ( i * 20 ) % 256; int b = ( i * 30 ) % 256; colors[i] = new Color(display,r,g,b); } Shell shell = new Shell(display); shell.setText("SlowRepaintTest"); ScrolledComposite comp = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); SlowRepaintingCanvas canvas = new SlowRepaintingCanvas(comp,SWT.NONE| SWT.NO_BACKGROUND); comp.setContent(canvas); canvas.setSize(5000,5000);
Daniel
source share