Package ca.cgjennings.ui
Class IconBorder
- java.lang.Object
-
- javax.swing.border.AbstractBorder
-
- ca.cgjennings.ui.IconBorder
-
- All Implemented Interfaces:
java.io.Serializable,javax.swing.border.Border
public class IconBorder extends javax.swing.border.AbstractBorderPaints an icon on the left or right side of a component, depending on reading direction. Intended to be used to add decorative icons to text fields.- Since:
- 3.0
- Author:
- Chris Jennings
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IconBorder()IconBorder(java.net.URL icon)IconBorder(java.net.URL icon, boolean showOnRightSide)IconBorder(javax.swing.Icon icon)IconBorder(javax.swing.Icon icon, boolean showOnRightSide)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static IconBorderapplyLabelBorder(javax.swing.JComponent target, java.lang.String prefix, javax.swing.Icon icon, javax.swing.Icon hoverIcon, java.awt.event.ActionListener li, javax.swing.JPopupMenu menu)java.awt.InsetsgetBorderInsets(java.awt.Component c)java.awt.InsetsgetBorderInsets(java.awt.Component c, java.awt.Insets insets)javax.swing.IcongetIcon()intgetInnerIconMargin()intgetOuterIconMargin()javax.swing.border.Borderinstall(javax.swing.JComponent c)Installs this border on a component by setting a new compound border on the component with the existing border on the outside and this border on the inside.javax.swing.border.BorderinstallClickable(javax.swing.JComponent c, javax.swing.Icon hoverIcon, java.awt.event.ActionListener li, javax.swing.JPopupMenu popupMenu)Installs this border on a component and makes the icon border clickable.booleanisBorderOpaque()booleanisIconOnRightSide()booleanisPointOverIcon(javax.swing.JComponent c, int x, int y)Assuming that a component has this border installed on it, returnstrueif a point in the component's coordinate space would be over the icon.voidpaintBorder(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)voidsetIcon(javax.swing.Icon icon)voidsetIconOnRightSide(boolean rightSide)voidsetInnerIconMargin(int gap)voidsetOuterIconMargin(int gap)
-
-
-
Constructor Detail
-
IconBorder
public IconBorder()
-
IconBorder
public IconBorder(javax.swing.Icon icon)
-
IconBorder
public IconBorder(java.net.URL icon)
-
IconBorder
public IconBorder(javax.swing.Icon icon, boolean showOnRightSide)
-
IconBorder
public IconBorder(java.net.URL icon, boolean showOnRightSide)
-
-
Method Detail
-
getIcon
public javax.swing.Icon getIcon()
-
setIcon
public void setIcon(javax.swing.Icon icon)
-
isIconOnRightSide
public boolean isIconOnRightSide()
-
setIconOnRightSide
public void setIconOnRightSide(boolean rightSide)
-
isPointOverIcon
public boolean isPointOverIcon(javax.swing.JComponent c, int x, int y)Assuming that a component has this border installed on it, returnstrueif a point in the component's coordinate space would be over the icon.- Parameters:
c- the component to testx- the x-coordinate of the pointy- the y-coordinate of the point- Returns:
trueif (x,y) is over the icon border
-
install
public javax.swing.border.Border install(javax.swing.JComponent c)
Installs this border on a component by setting a new compound border on the component with the existing border on the outside and this border on the inside. Returns the new compound border.If the component has no border, this border is simply set on the component without creating a compound border.
If the component is an editable combo box, the icon will be installed on the editor component if it is a
JComponent.- Parameters:
c- the component to install the border on, typically a text field- Returns:
- the installed compound border
-
installClickable
public javax.swing.border.Border installClickable(javax.swing.JComponent c, javax.swing.Icon hoverIcon, java.awt.event.ActionListener li, javax.swing.JPopupMenu popupMenu)Installs this border on a component and makes the icon border clickable. This behaves exactly as for callinginstall(javax.swing.JComponent), except that the border also responds to mouse events.- Parameters:
c- the component to install inhoverIcon- an optional alternate icon displayed when the pointer is over the iconli- an optional listener that will be called when the icon is left clickedpopupMenu- an optional popup menu that will be displayed when the icon is right clicked- Returns:
- the installed compound border
-
getBorderInsets
public java.awt.Insets getBorderInsets(java.awt.Component c)
- Specified by:
getBorderInsetsin interfacejavax.swing.border.Border- Overrides:
getBorderInsetsin classjavax.swing.border.AbstractBorder
-
getBorderInsets
public java.awt.Insets getBorderInsets(java.awt.Component c, java.awt.Insets insets)- Overrides:
getBorderInsetsin classjavax.swing.border.AbstractBorder
-
isBorderOpaque
public boolean isBorderOpaque()
- Specified by:
isBorderOpaquein interfacejavax.swing.border.Border- Overrides:
isBorderOpaquein classjavax.swing.border.AbstractBorder
-
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- Overrides:
paintBorderin classjavax.swing.border.AbstractBorder
-
setOuterIconMargin
public void setOuterIconMargin(int gap)
-
getOuterIconMargin
public int getOuterIconMargin()
-
setInnerIconMargin
public void setInnerIconMargin(int gap)
-
getInnerIconMargin
public int getInnerIconMargin()
-
applyLabelBorder
public static IconBorder applyLabelBorder(javax.swing.JComponent target, java.lang.String prefix, javax.swing.Icon icon, javax.swing.Icon hoverIcon, java.awt.event.ActionListener li, javax.swing.JPopupMenu menu)
-
-