Class IconBorder

All Implemented Interfaces:
Serializable, Border

public class IconBorder extends 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:
  • Constructor Details

    • IconBorder

      public IconBorder(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(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(Insets borderInsets, 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, 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 Details

    • 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(Component c, Graphics g, int x, int y, int width, int height)
      Specified by:
      paintBorder in interface Border
      Overrides:
      paintBorder in class MatteBorder