Home
Download
Change log
Java table layout manager
Introduction
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.
Features
• grid or table layout manager
• place widgets in any table rows and columns
• specify the alignment in a row (north, south, west, east)
• specify if a cell in the table can grow, specify a weight for growing if several cells can grow
• spawn a cell over rows/columns
• specify margin and spacing of cells
Requirements
Examples
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.setLayoutData(tableLayoutData);
button = new Button(shell,SWT.PUSH);
button.setText("Button right");
/* place button in cell 0,1 */
tableLayoutData = new TableLayoutData(0,1,TableLayoutData.WE);
button.setLayoutData(tableLayoutData);
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.setLayoutData(tableLayoutData);
label = new Label(composite,SWT.LEFT|SWT.BORDER);
label.setText("label 1.2");
tableLayoutData = new TableLayoutData(0,1,TableLayoutData.W);
label.setLayoutData(tableLayoutData);
}
shell.setSize(600,400);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch()) display.sleep();
}
}
}
Compile
Compile TableLayout.java and TableLayoutData.java with your project.
Note: please have a look in TableLayout.java and TableLayoutData.java
for details!
License
Table layout manager is currently under GPL version 2.
Download
tablelayout-0.04.tar.bz2
ChangeLog
2021-03-03 0.04
* added more alignments
* support invisible tabs, composites
* fixed layout for invisible composite
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