Java Reference
In-Depth Information
25.1. java.awt The Abstract Window Toolkit
The Abstract Window Toolkit allows you to write graphical user interfaces
( GUI s) that will run on every system in a reasonable way. The AWT displays
GUI components (such as buttons, labels, and text fields) using (by de-
fault) the local platform's look and feel, showing Macintosh buttons on
a Mac, Motif buttons on X platforms, Windows buttons on Windows sys-
tems, and so on.
For this to work, you may need to change how you think about laying out
your GUI . You may be accustomed to interactive tools that let you place
the various GUI components on the screen exactly where you want them
to be. Such absolute placement will not work for a portable interface be-
cause, for example, the size of a button is different on different systems.
When your interface is used on a system other than the one on which
you designed it, some buttons will overlap and others will have ugly gaps
between them.
Although you can use absolute placement in AWT , it is not recommended.
When you place a component into an AWT display frame, the frame's lay-
out manager decides where to put it. Almost all the layout managers
provided with the AWT use relative placement: Components are placed and
sized relative to other components. All the provided layout managers im-
plement either the interface LayoutManager or its extended interface Lay-
outManager2 . Layout managers range from the simple ( FlowLayout adds
components to a line until they don't fit and then starts a new line) to the
sophisticated ( GridBagLayout has a great deal of flexibility). You can also
write your own layout manager.
Instead of thinking about where a check box should go on the screen,
you should think about how it should be placed relative to other com-
ponents. Then choose a layout manager for the frame in which the check
box will be placed and add the components so that they have the expec-
ted relationships. If you do this right, your interface will look clean on all
platforms.
 
Search WWH ::




Custom Search