Java Reference
In-Depth Information
When this method returns
true
, the border needs to be opaque, filling its entire insets
area. When it returns
false
, any area not drawn will retain the background of the component
in which the border is installed.
Introducing BorderFactory
Now that you have a basic understanding of how the
Border
interface works, let's take a quick
look at the
BorderFactory
class as a means to create borders swiftly and easily. Found in the
javax.swing
package, the
BorderFactory
class offers a series of
static
methods for creating
predefined borders. Instead of laboriously calling the specific constructors for different borders,
you can create almost all the borders through this factory class. The factory class also caches
the creation of some borders to avoid re-creating commonly used borders multiple times. The
class definition follows.
public class BorderFactory {
public static Border createBevelBorder(int type);
public static Border createBevelBorder(int type, Color highlight,
Color shadow);
public static Border createBevelBorder(int type, Color highlightOuter,
Color highlightInner, Color shadowOuter, Color shadowInner);
public static CompoundBorder createCompoundBorder();
public static CompoundBorder createCompoundBorder(Border outside,
Border inside);
public static Border createEmptyBorder();
public static Border createEmptyBorder(int top, int left, int bottom,
int right);
public static Border createEtchedBorder();
public static Border createEtchedBorder(Color highlight, Color shadow);
public static Border createEtchedBorder(int type);
public static Border createEtchedBorder(int type, Color highlight,
Color shadow);
public static Border createLineBorder(Color color);
public static Border createLineBorder(Color color, int thickness);
public static Border createLoweredBevelBorder();
public static MatteBorder createMatteBorder(int top, int left, int bottom,
int right, Color color);
public static MatteBorder createMatteBorder(int top, int left, int bottom,
int right, Icon icon);