Package com.everdro1d.libs.swing
Class ImageUtils
java.lang.Object
com.everdro1d.libs.swing.ImageUtils
Utility class for handling image-related operations in Swing applications.
This class provides methods for setting frame icons, retrieving application icons, changing icon colors, and applying transformations such as darkening icons.
Features:
- Set the icon of a
JFrame
from application resources. - Retrieve an image as an
Icon
from the application's resources. - Change the color of an icon while preserving transparency.
- Darken an icon by reducing its brightness.
Example Usage:
JFrame frame = new JFrame(); ImageUtils.setFrameIcon(frame, "icons/app_icon.png", MyApp.class);
Note: This class cannot be instantiated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ImageIcon
changeIconColor
(Icon icon, Color color) Changes the color of a given icon to the specified color.static ImageIcon
darkenIcon
(Icon icon) Darkens the given icon by reducing the brightness of its colors.static Icon
getApplicationIcon
(String internalPath, Class<?> clazz) Retrieve an image as an Icon from the application's resources.static void
setFrameIcon
(JFrame frame, String internalPath, Class<?> clazz) Set the icon of the frame.
-
Method Details
-
setFrameIcon
Set the icon of the frame.- Parameters:
frame
- the frame to set the icon ofinternalPath
- path to the image file within resourcesclazz
- the class to trace from
-
getApplicationIcon
Retrieve an image as an Icon from the application's resources.- Parameters:
internalPath
- path to the image file within resourcesclazz
- the class to trace from- Returns:
- the Icon
-
changeIconColor
Changes the color of a given icon to the specified color.This method creates a new image from the provided icon and applies a color filter to replace the RGB values of non-transparent pixels with the specified color while preserving the alpha (transparency) values.
- Parameters:
icon
- the icon to change the color ofcolor
- the new color to apply to the icon- Returns:
- a new
ImageIcon
with the applied color, ornull
if an error occurs
-
darkenIcon
Darkens the given icon by reducing the brightness of its colors.This method creates a new image from the provided icon and applies a darker color transformation to each pixel while preserving the alpha (transparency) values.
- Parameters:
icon
- the icon to darken- Returns:
- a new
ImageIcon
with the darkened colors, ornull
if an error occurs
-