Home Download Change log


When I started to develop in Java SWT I missed a powerful grid or table layout manager like I knew it from e. g. TclTk. The included layout managers (row/column layout, grid layout, form layout) were not powerful enough for me and difficult to use. Thus I have written this table layout manager for Java SWT. The layout manager is a little bit designed like the grid layout manager of TclTk. I think this layout manager is more flexible and offer a better layout than the standard SWT layout managers. If you are looking for grid/table layout manager for SWT, feel free to use the library.




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

public class TableLayoutTest
  static Shell shell;
  static Button button3;

  public static void main(String[] args)
    Button button;
    Composite composite;
    Label label;
    TableLayoutData tableLayoutData;
    final Label resizeLabel;
    Canvas canvas;

    Display display = new Display();
    shell = new Shell(display);
    /* set layout for shell: row 1 can grow, columns 0 and 1 can grow with weightings 70% and 30% */
    shell.setLayout(new TableLayout(new double[]{0.0,1.0},new double[]{0.7,0.3},2));

    button = new Button(shell,SWT.PUSH);
    button.setText("Button left");
    /* place button in cell 0,0 */
    tableLayoutData = new TableLayoutData(0,0,TableLayoutData.W);

    button = new Button(shell,SWT.PUSH);
    button.setText("Button right");
    /* place button in cell 0,1 */
    tableLayoutData = new TableLayoutData(0,1,TableLayoutData.WE);

    composite = new Composite(shell,SWT.NONE);
    composite.setLayout(new TableLayout(new double[]{0.0,0.0},new double[]{1.0,1.0,1.0,1.0}));
    /* place composite in cell 1,0 */
    composite.setLayoutData(new TableLayoutData(1,0,TableLayoutData.WE));
      label = new Label(composite,SWT.LEFT|SWT.BORDER);
      label.setText("label 1.1 we");
      tableLayoutData = new TableLayoutData(0,0,TableLayoutData.WE);

      label = new Label(composite,SWT.LEFT|SWT.BORDER);
      label.setText("label 1.2");
      tableLayoutData = new TableLayoutData(0,1,TableLayoutData.W);


    while (!shell.isDisposed())
      if (!display.readAndDispatch()) display.sleep();


Note: please have a look in TableLayout.java and TableLayoutData.java for details!


Table layout manager is currently under GPL version 2.




2009-09-15 0.03
  * fix minimal compute size to avoid layout problems (e. g. usage of
    default size). Set minimal size to (1,1).

2009-02-13 0.02
  * removed EXPAND; not needed because you can specify e. g. WE and
    some expanding weight
  * several internal fixed in calculation of widgets size and position
    Now it should work pretty well!

2008-12-13 0.01
  * initial public release

Back to top