Child Component Sizes
Only a single child component is ever visible when a
CardLayout is used, and that component's size is set to the
container's available display area. The available display area is defined
as the container's dimensions minus its insets and any horizontal and
vertical gaps that should be placed around the edges of the child
components.
Child Component Locations
The single visible child component always fills the entire available
display area of the parent container, so its location is implicitly defined
to be the upper-left corner of the parent.
Resizing Behavior
The size of the component displayed is set to the container's available
display area. If the container's size increases or decreases, a
corresponding change occurs to the size of the displayed component.
Container Size
CardLayout identifies the preferred size of its container as
the largest preferred width and largest preferred height of any child
component. Similarly, the minimum size is equal to the largest minimum
width and height values returned by any of the container's child
components. The maximum size is effectively set to infinity, since
CardLayout's maximumLayoutSize() method returns
Integer.MAX_VALUE for both the maximum width and maximum
height, where Integer.MAX_VALUE is a constant that represents
the largest possible integer (that is, int or
Integer) value.
FlowLayout
The FlowLayout arranges the components in rows from left-to-
right and top-to-bottom order based on the order in which they were added
to the container, allowing each component to occupy as much or as little
space as it needs. This layout manager is useful when you wish to create a
collection of adjacent components that are all allowed to be displayed
using their default sizes.
Constructing a FlowLayout
When creating a new FlowLayout instance, you can specify the
alignment that should be used when positioning the child components. The
alignment value should correspond to one of the constants defined in
FlowLayout, specifically LEFT,
CENTER, or RIGHT. As mentioned previously,
FlowLayout arranges components in rows, and the alignment
specifies the alignment of the rows. For example, if you create a
FlowLayout that's left aligned, the components in each row
will appear next to the left edge of the container.
The FlowLayout constructors allow you to specify the
horizontal and vertical gaps that should appear between components, and if
you use a constructor that does not accept these values, they both default
to 5. Note that unlike the gaps used by some other layout managers, the
gaps generated by a FlowLayout appear not only between
adjacent components, but also between components and the edge of the
container.
To construct a FlowLayout that's right aligned and uses a horizontal gap of 10 pixels and vertical gap of 5
pixels between components, you can use the following code:
FlowLayout fl = new FlowLayout(FlowLayout.RIGHT, 10, 5);
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.