Java Reference
In-Depth Information
Cell Padding and Insets
The email panel example doesn't use three GridBagConstraints variables: insets ,
ipadx , and ipady . The ipadx and ipady constraints control padding , the extra space
around an individual component. By default, no components have extra space around
them (which is easiest to see in components that fill their cells). The ipadx variable adds
space to either side of the component, and ipady adds it above and below.
The horizontal and vertical gaps that appear when you create a new layout manager (or
use ipadx and ipady in grid bag layouts) are used to determine the amount of space
between components in a panel. Insets , however, are used to determine the amount of
space around the panel itself. The Insets class includes values for the top, bottom, left,
and right insets, which are then used when the panel itself is drawn.
Insets determine the amount of space between the edges of a panel and that panel's com-
ponents.
The following statement creates an Insets object that specifies 20 pixels of insets above
and below and 13 pixels to the left and right:
Insets whitespace = new Insets(20, 13, 20, 13);
Insets can be established in any container by overriding its getInsets() method and
returning an Insets object, as in this example:
11
public Insets getInsets() {
return new Insets(10, 30, 10, 30);
}
Summary
Abstract expressionism goes only so far, as you have seen today. Layout managers
require some adjustment for people who are used to more precise control over the place
that components appear on an interface.
You now know how to use the five different layout managers and panels. As you work
with the Abstract Windowing Toolkit, you'll find that it can approximate any kind of
interface through the use of nested containers and different layout managers.
After you master the development of a user interface in Java, your programs can offer
something that most other visual programming languages can't: an interface that works
on multiple platforms without modification.
 
Search WWH ::




Custom Search