Next page | Contents page |

Layout managers

The layout of components on a container is controlled by a LayoutManager object. The following are defined in awt:

Swing added BoxLayout which is easier.

Generally call pack () on a container after adding components.

	Container c = jframe.getContentPane ();
	c.setLayout (new FlowLayout ());
	c.add (button1);
	c.pack ();

javax.swing.JPanel

This is a Container that can be placed on a Container, to group controls together. It often provides a simple way of laying things out by just using the default BorderLayout. Eg,

	Container c = jframe.getContentPane ();
	JPanel top = new JPanel ();
	top.add (new JButton ("This"), BorderLayout.WEST);
	top.add (new JButton ("That"), BorderLayout.CENTER);
	top.add (new JButton ("Other"), BorderLayout.EAST);
	c.add (top, BorderLayout.NORTH);
	c.pack ();
Next page | Contents page |