Java Reference
In-Depth Information
When the BorderLayout is used, any add commands that are issued without
a String use "Center" as the default. If a String is provided but is not one of
the acceptable five (including having correct case), then a run-time exception
is thrown. 3
When the
BorderLayout is
used, an add com-
mand that is issued
without a String
defaults to
"Center" .
null layout
The null layout is used to perform precise positioning. In the null layout,
each object is added to the container by add . Its position and size may then be
set by calling the setBounds method:
The null layout is
used to perform
precise positioning.
void setBounds( int x, int y, int width, int height );
Here x and y represent the location of the upper left-hand corner of the object,
relative to the upper left-hand corner of its container. And width and height
represent the size of the object. All units are pixels.
The null layout is platform dependent; typically, this is a significant liability.
fancier layouts
Java also provides the CardLayout , GridLayout , and GridBagLayout . The
CardLayout simulates the tabbed index cards popular in Windows applications.
The GridLayout adds components into a grid but will make each grid entry the
same size. This means that components are stretched in sometimes unnatural
ways. It is useful for when this is not a problem, such as a calculator keypad
that consists of a two-dimensional grid of buttons. The GridBagLayout adds
components into a grid but allows components to cover several grid cells. It is
more complicated than the other layouts.
Other layouts simu-
late tabbed index
cards and allow
arranging over an
arbitrary grid.
visual tools
Commercial products include tools that allow the programmer to draw the
layout using a CAD-like system. The tool then produces the Java code to con-
struct the objects and provide a layout. Even with this system, the program-
mer must still write most of the code, including the handling of events, but is
relieved of the dirty work involved in calculating precise object positions.
3. Note that in Java 1.0, the arguments to add were reversed, and missing or incorrect Strings
were quietly ignored, thus leading to difficult debugging. The old style is still allowed, but it
is officially discouraged.
 
 
Search WWH ::




Custom Search