Java Reference
In-Depth Information
Examining the Predefined Borders
Now that the basics have been described, let's look at the specifics of each of the predefined
border classes, somewhat in order of complexity.
EmptyBorder Class
The empty border, logically enough, is a border with nothing drawn in it. You can use
EmptyBorder where you might have otherwise overridden insets() or getInsets() with a
regular AWT container. It allows you to reserve extra space around a component to spread your
screen components out a little or to alter centering or justification somewhat. Figure 7-3 shows
both an empty border and one that is not empty.
Figure 7-3. EmptyBorder sample, with insets of 20 for top and left, 0 for right and bottom
EmptyBorder has two constructors and two factory methods of BorderFactory:
public static Border createEmptyBorder()
Border emptyBorder = BorderFactory.createEmptyBorder();
public static Border createEmptyBorder(int top, int left, int bottom, int right)
Border emptyBorder = BorderFactory.createEmptyBorder(5, 10, 5, 10);
public EmptyBorder(Insets insets)
Insets insets = new Insets(5, 10, 5, 10);
Border EmptyBorder = new EmptyBorder(insets);
public EmptyBorder(int top, int left, int bottom, int right)
Border EmptyBorder = new EmptyBorder(5, 10, 5, 10);
Each allows you to customize the border insets in its own manner. The no-argument
version creates a truly empty border with zero insets all around; otherwise, you can specify the
insets as either an AWT Insets instance or as the inset pieces. The EmptyBorder is transparent
by default.
 
Search WWH ::




Custom Search