Class FlatAbstractIcon

java.lang.Object
com.formdev.flatlaf.icons.FlatAbstractIcon
All Implemented Interfaces:
Icon, UIResource
Direct Known Subclasses:
FlatAnimatedIcon, FlatAscendingSortIcon, FlatCapsLockIcon, FlatCheckBoxIcon, FlatCheckBoxMenuItemIcon, FlatClearIcon, FlatFileChooserDetailsViewIcon, FlatFileChooserHomeFolderIcon, FlatFileChooserListViewIcon, FlatFileChooserNewFolderIcon, FlatFileChooserUpFolderIcon, FlatFileViewComputerIcon, FlatFileViewDirectoryIcon, FlatFileViewFileIcon, FlatFileViewFloppyDriveIcon, FlatFileViewHardDriveIcon, FlatHelpButtonIcon, FlatInternalFrameAbstractIcon, FlatMenuArrowIcon, FlatMenuItemArrowIcon, FlatOptionPaneAbstractIcon, FlatRevealIcon, FlatSearchIcon, FlatTabbedPaneCloseIcon, FlatTreeClosedIcon, FlatTreeCollapsedIcon, FlatTreeLeafIcon, FlatTreeOpenIcon, FlatWindowAbstractIcon

public abstract class FlatAbstractIcon extends Object implements Icon, UIResource
Base class for icons that scales width and height, creates and initializes a scaled graphics context for icon painting.

Subclasses do not need to scale icon painting.

  • Field Details

    • width

      protected final int width
      Unscaled icon width.
    • height

      protected final int height
      Unscaled icon height.
    • color

      protected Color color
  • Constructor Details

    • FlatAbstractIcon

      public FlatAbstractIcon(int width, int height, Color color)
  • Method Details

    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      Specified by:
      paintIcon in interface Icon
    • paintBackground

      protected void paintBackground(Component c, Graphics2D g, int x, int y)
      Paints icon background. Default implementation does nothing. Can be overridden to paint specific icon background.

      The bounds of the area to be filled are: x, y, getIconWidth(), getIconHeight().

      In contrast to paintIcon(Component, Graphics2D), the graphics context g is not translated and not scaled.

      Since:
      3.5.2
    • paintIcon

      protected abstract void paintIcon(Component c, Graphics2D g)
      Paints icon.

      The graphics context is translated and scaled. This means that icon x,y coordinates are 0,0 and it is not necessary to scale coordinates within this method.

      The bounds to be used for icon painting are: 0, 0, width, height.

    • getIconWidth

      public int getIconWidth()
      Returns the scaled icon width.
      Specified by:
      getIconWidth in interface Icon
    • getIconHeight

      public int getIconHeight()
      Returns the scaled icon height.
      Specified by:
      getIconHeight in interface Icon
    • getScale

      public float getScale()
      Since:
      3.7
    • setScale

      public void setScale(float scale)
      Since:
      3.7
    • scale

      protected int scale(int size)
      Multiplies the given value by the icon scale factor getScale() and rounds the result.

      If you want scale a float or double value, simply use: myFloatValue * getScale().

      Do not use this method when painting icon in paintIcon(Component, Graphics2D).

      Since:
      3.7