Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Composite is slow to draw
Composite is slow to draw [message #762799] Thu, 08 December 2011 16:26
Oliver Buckley is currently offline Oliver BuckleyFriend
Messages: 1
Registered: December 2011
Junior Member
I'm creating a very simple class using SWT that essentially creates a grid of 96 cells. Each of these cells contains 3 buttons (split over two composites). The problem that I am having is that when the composite is drawn it is very slow (i.e. you can see the controls being drawn from bottom to top).

Is there a limit on the number of controls that you can sensibly use in a GridLayout or on a composite and I've just reached that limit (there's around 300 buttons, each of which has a composite associated with it). I've done something similar in Swing and it's fine...

I've attached a stripped down version of what I'm doing, hopefully someone can point me in the right direction?

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class GridComposite extends Composite {
	
	private static final int ROWS = 12;
	private static final int COLUMNS = 8;
		
	public GridComposite(Composite parent, int style) {
		super(parent, style);
		
		setLayout(createGridLayout(COLUMNS, true));
		
		Composite[] childComp = new Composite[COLUMNS * ROWS];
		GridLayout parentLayout = createGridLayout(2, false);
		GridLayout childLayout = createGridLayout(1, false);
		
		for (int row = 0; row < ROWS; row++) {
			for (int column = 0; column < COLUMNS; column++) {
				String columnName = String.valueOf((char) (column+1 + 64));
				int current = (row + column) + (row * (COLUMNS-1));

				childComp[current] = new Composite(this, SWT.BORDER);
				childComp[current].setLayout(parentLayout);
				childComp[current].setLayoutData(new GridData());

				Composite leftComposite = new Composite(childComp[current], SWT.NONE);
				leftComposite.setLayout(childLayout);
				leftComposite.setLayoutData(new GridData());
				Button button = new Button(leftComposite, SWT.PUSH);
				button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
				button.setText(columnName + (row+1));

				Composite rightComposite = new Composite(childComp[current], SWT.NONE);
				rightComposite.setLayout(childLayout);
				rightComposite.setLayoutData(new GridData());
				
				Button button2 = new Button(rightComposite, SWT.PUSH);
				button2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
				button2.setText("o");
				
				Button button3 = new Button(rightComposite, SWT.PUSH);
				button3.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
				button3.setText("o");
			}
		}
	}
	
	private GridLayout createGridLayout(int columns, boolean makeColumnsEqual) {
		GridLayout grid = new GridLayout(columns, makeColumnsEqual);
		grid.horizontalSpacing = 0;
		grid.verticalSpacing = 0;
		grid.marginHeight = 0;
		grid.marginWidth = 0;
		
		return grid;
	}

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());
		
		GridComposite psc = new GridComposite(shell, SWT.NONE);
		psc.setVisible(true);
		
		shell.setLocation(400,400);
		shell.pack();
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) shell.getDisplay().sleep();
		}
		
		display.dispose();
	}
}

Previous Topic:Unable to hide icon in dock for SWT bundled application
Next Topic:X Resource Class Names
Goto Forum:
  


Current Time: Thu Apr 25 00:44:27 GMT 2024

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

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

Back to the top