Java Utililty Methods Swing Icon

List of utility methods to do Swing Icon

Description

The list of methods to do Swing Icon are organized into topic(s).

Method

IcongetIconFromExtension(String f, boolean folder)
get Icon From Extension
if (folder) {
    return getFolderIcon();
} else {
    return getIconFromExtension(f);
ImageIcongetIconInterTrial()
get Icon Inter Trial
if (ICON_INTERTRIAL == null) {
    File iconInterTrialFile = new File("icons" + File.separator + "intertrial.png");
    try {
        ICON_INTERTRIAL = new ImageIcon(iconInterTrialFile.toURI().toURL());
    } catch (MalformedURLException e) {
        e.printStackTrace();
return ICON_INTERTRIAL;
ImagegetIcono()
Imagen de icono para la ventana principal
URL urlDeLaImagen = Main.class.getClassLoader().getResource("images/icon.png");
ImageIcon img = new ImageIcon(urlDeLaImagen);
return img.getImage();
ImageIcongetPressedExitIcon(int x, int y)
get Pressed Exit Icon
if (PressedExit == null) {
    PressedExit = new ImageIcon(IMAGE_FOLDER + PRESSED_EXIT_IMAGE);
return prepareImage(PressedExit, y, x);
IcongetResourceIcon(Object target, String name)
{ method
return (getResourceIcon(target.getClass(), name));
ImageIcongetScaledIcon(Icon icon)
Get a scaled icon starting from an icon.
int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
int scale = 2;
int scaledIconWidth = iconWidth / scale;
int scaledIconHeight = iconHeight / scale;
BufferedImage bufferedImage = new BufferedImage(scaledIconWidth, scaledIconHeight,
        BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
...
IcongetScaledIcon(Icon tmpIcon, int w, int h, boolean incr)
get Scaled Icon
ImageIcon ii = null;
if (tmpIcon instanceof ImageIcon) {
    return getScaledImageIcon((ImageIcon) tmpIcon, w, h, incr);
return tmpIcon;
ImageIcongetScaledIcon(String resourceName, int width, int height)
Used to get an icon with specified width and height.
ImageIcon result = getImageIcon(resourceName);
if (result != null) {
    if (width > 0 && height > 0) {
        Image artImage = result.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
        result.setImage(artImage);
return result;
...
int[]getSize(String graphIconPath)
Retrieve image size's
if (graphIconPath != null && !graphIconPath.isEmpty()) {
    ImageIcon image = new ImageIcon(graphIconPath);
    return new int[] { image.getIconWidth(), image.getIconHeight() };
} else {
    return new int[] { 150, 75 };
ImageIcongetTransparentIcon(int width)
get Transparent Icon
switch (width) {
case ICON_SIZE_SMALL:
    return ICON_TRANSPARENT_SMALL;
case ICON_SIZE_MEDIUM:
    return ICON_TRANSPARENT_MEDIUM;
case ICON_SIZE_LARGE:
    return ICON_TRANSPARENT_LARGE;
default:
...