Java Glossary : Layout

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : L words : Layout.

Layout
a method that fine tunes the sizes and positions of a group of graphical elements from a few rough hints on how you want the layout done. You can roll your own layout manager, or use one of the standard ones. Have a look at Sun's tutorial on layout managers. Beware, Sun's tutorial talks in terms of JDK 1.1.5. Peter Haggar has written a most excellent Freelance Presentation and GridBag tutorial in MS Word format. Here is my general understanding of Layouts. Each component has four sizes (height,width).

These methods often return 0,0 as the size. The reason is, they rely on the underlying GUI to compute the size, and if there in no peer object yet, there is no hook to ask the native GUI. See addNotify.

A layout manager basically does a setBounds(x, y, width, height) on each component in a container, which sets the component's actual size and location. The routine in the LayoutManager that actually assigns co-ordinates and sizes to each component is called:

However the container as a whole also needs a getMinimumSize(), getMaximumSize() and getPreferredSize() method too, since it acts a component in an enclosing container. So the layout manager also needs to provide generic routines for computing the desired size of the container by totalling up the sizes of the contained components taking into consideration how they are packed in. These routines are indirectly used by another higher level layout manager. The routines that compute the sizes of an entire container are called: If you want to do absolute pixel positioning, without a layout manager, you must do setLayout( null ). This is trickier than you might imagine. See the gotchas. You are better off writing your own custom LayoutManager.

Layout Purpose
AbsoluteLayout Netbeans absolute position layout.
BorderLayout Place components on a simple north, south, east, west, center grid.
BoxLayout Place components in a single row or column. Designed to work with glue and strut objects of the Box class to control where extra space goes. Aligns based on the Component.getAlignmentX and Component.getAlignmentY properties of the Components in the Container. To control alignment use Component.setAlignment( 0.0F ) for left aligned, setAlignmentX( .5F ) for centered and setAlignmentX( 1.0F ) for right aligned.
CardLayout Allows you to flip through several panels, where only one is visible at a time.
EasyLayout Stripped down GridBagLayout. Has just weights, and grid numbers.
ExplicitLayout Allows non-rectangular layouts. By Zooki Technology.
FillLayout SWT. lays out equal-sized widgets in a single row or column.
FlowLayout Simple flow left to right, top to bottom stream of components.
FormLayout Karsten Lentzsch's LayoutManager.
GridBagLayout Place components on a rough n x m grid. Some components may take up multiple cells. Fine tuning of whitespace around each component and alignment of each component within its grid cell. Requires a lot of tweaking to make it look right. The cells are not necessarily the same size. They adjust to fit the components, based on various hints you give.
GridLayout Layout components in a regular n x m grid. All cells are the same width and height.
GridLayout SWT. lays out widgets in a grid FormLayout
HIGLayout Similar to TableLayout, by Daniel Michelik
LabeledGridBagLayout Like a GridBagLayout that automatically labels fields with their corresponding field names. Requires use of smart components that know their field labels. Part of the com.mindprod.business package.
PackerLayout A Java version of the Tcl/Tk layout manager. Some of the GridBag pad/expand abilities.
RowLayout SWT. lays out widgets in a row or rows, with fill, wrap, and spacing options.
SpringLayout Uses a model of structs and springs to control the sizes and positions of boxes.
StarLayout Arranges objects in star shaped patterns. You place by giving the angle and radius from the centre of the container. Contact me if interested.
TableLayout A simplified GridBagLayout. You explicitly control the relative sizes of each row and column. By Daniel Barbalace and The TableLayout Project.
XYLayout Borland absolute position layout.

// There are two ways to get your constraints to the Layout.
( (GridBagLayout) ( contentpane.getLayout() ) ).setConstraints( myComponent ,
                                                                theConstraints );
contentpane.add ( myComponent );

// or more simply
contenpane.add ( myComponent , theConstraints );

NetBeans and JBuilder have GUI layout builders. Radical is a stand-alone GUI Builder.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 3456.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/layout.html J:\mindprod\jgloss\layout.html