Class SwingIcon

java.lang.Object
com.jformdesigner.model.SwingIcon
All Implemented Interfaces:
SwingResource, Icon

public class SwingIcon extends Object implements Icon, SwingResource
Used to specify a Icon. The icon is either loaded from the classpath using new ImageIcon(classLoader.getResource(name)), from the file system using new ImageIcon(name) or from the current look and feel using UIManager.getIcon(name).
  • Field Details

  • Constructor Details

    • SwingIcon

      public SwingIcon(int type, String name)
      Constructs a icon.
      Parameters:
      type - The icon type (CLASSPATH, FILE or SWING).
      name - The icon name. A resource name (see java.lang.ClassLoader.getResource(String)) if type is CLASSPATH, a file name (see javax.swing.ImageIcon(String)) if type is FILE or a key (see javax.swing.UIManager.getIcon(String)) if type is SWING.
    • SwingIcon

      public SwingIcon(int type, String name, int width, int height, float scale)
      Constructs a icon including SVG icon options.
      Parameters:
      type - The icon type (CLASSPATH, FILE or SWING).
      name - The icon name. A resource name (see java.lang.ClassLoader.getResource(String)) if type is CLASSPATH, a file name (see javax.swing.ImageIcon(String)) if type is FILE or a key (see javax.swing.UIManager.getIcon(String)) if type is SWING.
      width - Custom SVG icon width, or -1.
      height - Custom SVG icon height, or -1.
      scale - Custom SVG icon scale factor, or 1.
      Since:
      8.3
    • SwingIcon

      public SwingIcon(int type, String name, int width, int height, float scale, Color fromColor, Color toLightColor, Color toDarkColor)
      Constructs a icon including SVG icon options.
      Parameters:
      type - The icon type (CLASSPATH, FILE or SWING).
      name - The icon name. A resource name (see java.lang.ClassLoader.getResource(String)) if type is CLASSPATH, a file name (see javax.swing.ImageIcon(String)) if type is FILE or a key (see javax.swing.UIManager.getIcon(String)) if type is SWING.
      width - Custom SVG icon width, or -1.
      height - Custom SVG icon height, or -1.
      scale - Custom SVG icon scale factor, or 1.
      fromColor - Custom SVG icon color that is mapped to toLightColor or toDarkColor, or null. If null, all colors in the SVG are mapped.
      toLightColor - Custom SVG icon color for light themes, or null.
      toDarkColor - Custom SVG icon color for dark themes, or null. If null, toLightColor is used.
      Since:
      8.3
  • Method Details

    • getType

      public int getType()
      Returns the icon type (CLASSPATH, FILE or SWING).
    • getName

      public String getName()
      Returns the icon name. A resource name if type is CLASSPATH, a file name if type is FILE or a key if type is SWING.
    • getWidth

      public int getWidth()
      Returns the custom SVG icon width. Or -1 to use default width specified in SVG icon.
      Since:
      8.3
    • getHeight

      public int getHeight()
      Returns the custom SVG icon height. Or -1 to use default height specified in SVG icon.
      Since:
      8.3
    • getScale

      public float getScale()
      Returns the amount by which the SVG icon size is scaled. Usually 1.
      Since:
      8.3
    • getFromColor

      public Color getFromColor()
    • getToLightColor

      public Color getToLightColor()
    • getToDarkColor

      public Color getToDarkColor()
    • createIcon

      public Icon createIcon(ClassLoader loader)
      For internal use only.
    • getIconWidth

      public int getIconWidth()
      Specified by:
      getIconWidth in interface Icon
    • getIconHeight

      public int getIconHeight()
      Specified by:
      getIconHeight in interface Icon
    • paintIcon

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

      public boolean equals(Object obj)
      Determines whether another object is equal to this object.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns the hash code for this object.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object