org.jdesktop.swingx.border
Class IconBorder

java.lang.Object
  extended by org.jdesktop.swingx.border.IconBorder
All Implemented Interfaces:
Serializable, Border

public class IconBorder
extends Object
implements Border, Serializable

IconBorder creates a border that places an Icon in the border on the horizontal axis. The border does not add any additional insets other than the inset required to produce the space for the icon. If additional insets are required, users should create a compund border.

This border is useful when attempting to add Icons to pre-existing components without requiring specialty painting.

See Also:
Serialized Form

Field Summary
static Icon EMPTY_ICON
          An empty icon.
 
Constructor Summary
IconBorder()
          Creates an IconBorder with an empty icon in a trailing position with a padding of 4.
IconBorder(Icon validIcon)
          Creates an IconBorder with the specified icon in a trailing position with a padding of 4.
IconBorder(Icon validIcon, int iconPosition)
          Creates an IconBorder with the specified constraints and a padding of 4.
IconBorder(Icon validIcon, int iconPosition, int padding)
          Creates an IconBorder with the specified constraints.
 
Method Summary
 Insets getBorderInsets(Component c)
          Returns the insets of the border.
 int getIconPosition()
          Returns the position to place the icon (relative to the component contents).
 int getPadding()
          Gets the padding surrounding the icon.
 boolean isBorderOpaque()
          This border is not opaque.
 void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
          Paints the border for the specified component with the specified position and size.
 void setIcon(Icon validIcon)
          Sets the icon for this border.
 void setIconPosition(int iconPosition)
          Sets the position to place the icon (relative to the component contents).
 void setPadding(int padding)
          Sets the padding around the icon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ICON

public static final Icon EMPTY_ICON
An empty icon.

Constructor Detail

IconBorder

public IconBorder()
Creates an IconBorder with an empty icon in a trailing position with a padding of 4.

See Also:
EMPTY_ICON

IconBorder

public IconBorder(Icon validIcon)
Creates an IconBorder with the specified icon in a trailing position with a padding of 4.

Parameters:
validIcon - the icon to set. This may be null to represent an empty icon.
See Also:
EMPTY_ICON

IconBorder

public IconBorder(Icon validIcon,
                  int iconPosition)
Creates an IconBorder with the specified constraints and a padding of 4.

Parameters:
validIcon - the icon to set. This may be null to represent an empty icon.
iconPosition - the position to place the icon relative to the component contents. This must be one of the following SwingConstants:
  • LEADING
  • TRAILING
  • EAST
  • WEST
Throws:
IllegalArgumentException - if iconPosition is not a valid position.
See Also:
EMPTY_ICON

IconBorder

public IconBorder(Icon validIcon,
                  int iconPosition,
                  int padding)
Creates an IconBorder with the specified constraints. If validIcon is null, EMPTY_ICON is used instead. If padding is negative, then the border does not use padding.

Parameters:
validIcon - the icon to set. This may be null to represent an empty icon.
iconPosition - the position to place the icon relative to the component contents. This must be one of the following SwingConstants:
  • LEADING
  • TRAILING
  • EAST
  • WEST
padding - the padding to surround the icon with. All non-positive values set the padding to 0.
Throws:
IllegalArgumentException - if iconPosition is not a valid position.
See Also:
EMPTY_ICON
Method Detail

getBorderInsets

public Insets getBorderInsets(Component c)
Returns the insets of the border.

Specified by:
getBorderInsets in interface Border
Parameters:
c - the component for which this border insets value applies

setIcon

public void setIcon(Icon validIcon)
Sets the icon for this border.

Parameters:
validIcon - the icon to set. This may be null to represent an empty icon.
See Also:
EMPTY_ICON

isBorderOpaque

public boolean isBorderOpaque()
This border is not opaque.

Specified by:
isBorderOpaque in interface Border
Returns:
always returns false

paintBorder

public void paintBorder(Component c,
                        Graphics g,
                        int x,
                        int y,
                        int width,
                        int height)
Paints the border for the specified component with the specified position and size.

Specified by:
paintBorder in interface Border
Parameters:
c - the component for which this border is being painted
g - the paint graphics
x - the x position of the painted border
y - the y position of the painted border
width - the width of the painted border
height - the height of the painted border

getPadding

public int getPadding()
Gets the padding surrounding the icon.

Returns:
the padding for the icon. This value is guaranteed to be nonnegative.

setPadding

public void setPadding(int padding)
Sets the padding around the icon.

Parameters:
padding - the padding to set. If padding < 0, then padding will be set to 0.

getIconPosition

public int getIconPosition()
Returns the position to place the icon (relative to the component contents).

Returns:
one of the following SwingConstants:
  • LEADING
  • TRAILING
  • EAST
  • WEST

setIconPosition

public void setIconPosition(int iconPosition)
Sets the position to place the icon (relative to the component contents).

Parameters:
iconPosition - must be one of the following SwingConstants:
  • LEADING
  • TRAILING
  • EAST
  • WEST
Throws:
IllegalArgumentException - if iconPosition is not a valid position.