Package org.jdesktop.swingx.border
Class IconBorder
- java.lang.Object
-
- org.jdesktop.swingx.border.IconBorder
-
- All Implemented Interfaces:
java.io.Serializable,javax.swing.border.Border
public class IconBorder extends java.lang.Object implements javax.swing.border.Border, java.io.SerializableIconBordercreates a border that places anIconin 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 acompund border.This border is useful when attempting to add
Icons to pre-existing components without requiring specialty painting.- Version:
- 1.1
- Author:
- Amy Fowler, Karl Schaefer
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static javax.swing.IconEMPTY_ICONAn empty icon.
-
Constructor Summary
Constructors Constructor Description IconBorder()Creates anIconBorderwith an empty icon in a trailing position with a padding of 4.IconBorder(javax.swing.Icon validIcon)Creates anIconBorderwith the specified icon in a trailing position with a padding of 4.IconBorder(javax.swing.Icon validIcon, int iconPosition)Creates anIconBorderwith the specified constraints and a padding of 4.IconBorder(javax.swing.Icon validIcon, int iconPosition, int padding)Creates anIconBorderwith the specified constraints.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.InsetsgetBorderInsets(java.awt.Component c)intgetIconPosition()Returns the position to place the icon (relative to the component contents).intgetPadding()Gets the padding surrounding the icon.booleanisBorderOpaque()This border is not opaque.voidpaintBorder(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)voidsetIcon(javax.swing.Icon validIcon)Sets the icon for this border.voidsetIconPosition(int iconPosition)Sets the position to place the icon (relative to the component contents).voidsetPadding(int padding)Sets the padding around the icon.
-
-
-
Constructor Detail
-
IconBorder
public IconBorder()
Creates anIconBorderwith an empty icon in a trailing position with a padding of 4.- See Also:
EMPTY_ICON
-
IconBorder
public IconBorder(javax.swing.Icon validIcon)
Creates anIconBorderwith the specified icon in a trailing position with a padding of 4.- Parameters:
validIcon- the icon to set. This may benullto represent an empty icon.- See Also:
EMPTY_ICON
-
IconBorder
public IconBorder(javax.swing.Icon validIcon, int iconPosition)Creates anIconBorderwith the specified constraints and a padding of 4.- Parameters:
validIcon- the icon to set. This may benullto represent an empty icon.iconPosition- the position to place the icon relative to the component contents. This must be one of the followingSwingConstants:LEADINGTRAILINGEASTWEST
- Throws:
java.lang.IllegalArgumentException- ificonPositionis not a valid position.- See Also:
EMPTY_ICON
-
IconBorder
public IconBorder(javax.swing.Icon validIcon, int iconPosition, int padding)Creates anIconBorderwith the specified constraints. IfvalidIconisnull,EMPTY_ICONis used instead. Ifpaddingis negative, then the border does not use padding.- Parameters:
validIcon- the icon to set. This may benullto represent an empty icon.iconPosition- the position to place the icon relative to the component contents. This must be one of the followingSwingConstants:LEADINGTRAILINGEASTWEST
padding- the padding to surround the icon with. All non-positive values set the padding to 0.- Throws:
java.lang.IllegalArgumentException- ificonPositionis not a valid position.- See Also:
EMPTY_ICON
-
-
Method Detail
-
getBorderInsets
public java.awt.Insets getBorderInsets(java.awt.Component c)
- Specified by:
getBorderInsetsin interfacejavax.swing.border.Border
-
setIcon
public void setIcon(javax.swing.Icon validIcon)
Sets the icon for this border.- Parameters:
validIcon- the icon to set. This may benullto represent an empty icon.- See Also:
EMPTY_ICON
-
isBorderOpaque
public boolean isBorderOpaque()
This border is not opaque.- Specified by:
isBorderOpaquein interfacejavax.swing.border.Border- Returns:
- always returns
false
-
paintBorder
public void paintBorder(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)- Specified by:
paintBorderin interfacejavax.swing.border.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. Ifpadding < 0, thenpaddingwill be set to0.
-
getIconPosition
public int getIconPosition()
Returns the position to place the icon (relative to the component contents).- Returns:
- one of the following
SwingConstants:LEADINGTRAILINGEASTWEST
-
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 followingSwingConstants:LEADINGTRAILINGEASTWEST
- Throws:
java.lang.IllegalArgumentException- ificonPositionis not a valid position.
-
-