Package smile.swing

Class AlphaIcon

java.lang.Object
smile.swing.AlphaIcon
All Implemented Interfaces:
Icon

public class AlphaIcon extends Object implements Icon
An Icon wrapper that paints the contained icon with a specified transparency.

Note: This class is not suitable for wrapping an ImageIcon that holds an animated image.

  • Constructor Details

    • AlphaIcon

      public AlphaIcon(Icon icon, float alpha)
      Creates an AlphaIcon with the specified icon and opacity. The opacity alpha should be in the range 0.0F (fully transparent) to 1.0F (fully opaque).
      Parameters:
      icon - the Icon to wrap
      alpha - the opacity
  • Method Details

    • getAlpha

      public float getAlpha()
      Gets this AlphaIcon's opacity
      Returns:
      the opacity, in the range 0.0 to 1.0
    • getIcon

      public Icon getIcon()
      Gets the icon wrapped by this AlphaIcon
      Returns:
      the wrapped icon
    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      Paints the wrapped icon with this AlphaIcon's transparency.
      Specified by:
      paintIcon in interface Icon
      Parameters:
      c - The component to which the icon is painted
      g - the graphics context
      x - the X coordinate of the icon's top-left corner
      y - the Y coordinate of the icon's top-left corner
    • getIconWidth

      public int getIconWidth()
      Gets the width of the bounding rectangle of this AlphaIcon. Returns the width of the wrapped icon.
      Specified by:
      getIconWidth in interface Icon
      Returns:
      the width in pixels
    • getIconHeight

      public int getIconHeight()
      Gets the height of the bounding rectangle of this AlphaIcon. * Returns the height of the wrapped icon.
      Specified by:
      getIconHeight in interface Icon
      Returns:
      the height in pixels