Class IconBorder

  • All Implemented Interfaces:
    java.io.Serializable, javax.swing.border.Border

    public class IconBorder
    extends javax.swing.border.MatteBorder
    IconBorder creates a border that places an Icon in the border on one or several sides. For example, if you want to an icon on the left side, you make the left inset to be the width of the icon, and 0 for the top, right and bottom insets. Then you can call setHorizontalIconAlignment(int) and set it to TOP or CENTER or BOTTOM.

    This border is useful when attempting to add Icons to pre-existing components without requiring specialty painting. For example, use in the CellStyle to decorate the cell renderer with an icon.

    Since:
    3.3.3
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.swing.border.MatteBorder

        color, tileIcon
      • Fields inherited from class javax.swing.border.EmptyBorder

        bottom, left, right, top
    • Constructor Summary

      Constructors 
      Constructor Description
      IconBorder​(int top, int left, int bottom, int right, javax.swing.Icon icon)
      Creates an IconBorder.
      IconBorder​(java.awt.Insets borderInsets, javax.swing.Icon icon)
      Creates an IconBorder.
      IconBorder​(javax.swing.Icon icon)
      Creates an IconBorder with an icon.
      IconBorder​(javax.swing.Icon icon, int verticalIconAlignment)
      Creates an IconBorder with an icon.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getHorizontalIconAlignment()
      Gets the icon alignment on the x axis.
      int getVerticalIconAlignment()
      Gets the icon alignment on the y axis.
      void paintBorder​(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)  
      void setHorizontalIconAlignment​(int horizontalIconAlignment)
      Sets the alignment of the icon relative to the component contents.
      void setVerticalIconAlignment​(int verticalIconAlignment)
      Sets the alignment of the icon relative to the component contents.
      • Methods inherited from class javax.swing.border.MatteBorder

        getBorderInsets, getBorderInsets, getMatteColor, getTileIcon, isBorderOpaque
      • Methods inherited from class javax.swing.border.AbstractBorder

        getBaseline, getBaselineResizeBehavior, getBorderInsets, getInteriorRectangle, getInteriorRectangle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IconBorder

        public IconBorder​(javax.swing.Icon icon)
        Creates an IconBorder with an icon. The right inset is the same as the icon width and 0 for all other insets. The vertical icon alignment is set to TOP by default.
        Parameters:
        icon - the icon.
      • IconBorder

        public IconBorder​(javax.swing.Icon icon,
                          int verticalIconAlignment)
        Creates an IconBorder with an icon. The right inset is the same as the icon width and 0 for all other insets.
        Parameters:
        icon - the icon.
        verticalIconAlignment - the vertical icon alignment.
      • IconBorder

        public IconBorder​(java.awt.Insets borderInsets,
                          javax.swing.Icon icon)
        Creates an IconBorder. The icon alignment is set to either TOP or TRAILING depending on value of the insets.
        Parameters:
        borderInsets - the insets of the border.
        icon - the icon
      • IconBorder

        public IconBorder​(int top,
                          int left,
                          int bottom,
                          int right,
                          javax.swing.Icon icon)
        Creates an IconBorder. The icon alignment is set to either TOP or TRAILING depending on value of the insets.
        Parameters:
        top - the top inset of the border
        left - the left inset of the border
        bottom - the bottom inset of the border
        right - the right inset of the border
        icon - the icon.
    • Method Detail

      • getHorizontalIconAlignment

        public int getHorizontalIconAlignment()
        Gets the icon alignment on the x axis. It is used to paint the icon when the top or bottom insets are not 0.
        Returns:
        the horizontal icon alignment.
      • setHorizontalIconAlignment

        public void setHorizontalIconAlignment​(int horizontalIconAlignment)
        Sets the alignment of the icon relative to the component contents. This must be one of the following SwingConstants:
         
        • LEADING: respects the component orientation
        • TRAILING: respects the component orientation
        • LEFT
        • RIGHT
        • CENTER
        Parameters:
        horizontalIconAlignment - one of the five SwingConstants listed above.
      • getVerticalIconAlignment

        public int getVerticalIconAlignment()
        Gets the icon alignment on the y axis. It is used to paint the icon when the left or right insets are not 0.
        Returns:
        the vertical icon alignment.
      • setVerticalIconAlignment

        public void setVerticalIconAlignment​(int verticalIconAlignment)
        Sets the alignment of the icon relative to the component contents. This must be one of the following SwingConstants:
         
        • TOP
        • BOTTOM
        • CENTER
        Parameters:
        verticalIconAlignment - one of the three SwingConstants listed above.
      • paintBorder

        public void paintBorder​(java.awt.Component c,
                                java.awt.Graphics g,
                                int x,
                                int y,
                                int width,
                                int height)
        Specified by:
        paintBorder in interface javax.swing.border.Border
        Overrides:
        paintBorder in class javax.swing.border.MatteBorder