Java Reference
In-Depth Information
■
Note
When creating an empty border, with zeros all around, you should use the factory method to create
the border, avoiding the direct constructors. This allows the factory to create one truly empty border to be
shared by all. If all you want to do is hide the border, and the component is an
AbstractButton
subclass,
just call
setBorderPainted(false)
.
LineBorder Class
The line border is a single-color line of a user-defined thickness that surrounds a component.
It can have squared-off or rounded corners. If you want to alter the thickness on different sides,
you'll need to use
MatteBorder
, which is described in the section “Matte Border Class” later in
this chapter. Figure 7-4 shows a sampling of using
LineBorder
, with 1- and 12-pixel line thick-
nesses, with and without rounded corners.
Figure 7-4.
LineBorder sample
Creating Line Borders
The
LineBorder
class has three constructors, two factory methods within it, and two factory
methods of
BorderFactory
:
public LineBorder(Color color)
Border lineBorder = new LineBorder (Color.RED);
public LineBorder(Color color, int thickness)
Border lineBorder = new LineBorder (Color.RED, 5);
public LineBorder (Color color, int thickness, boolean roundedCorners)
Border lineBorder = new LineBorder (Color.RED, 5, true);
public static Border createBlackLineBorder()
Border blackLine = LineBorder.createBlackLineBorder();