Java Swing Icon combineIcons(Icon underIcon, Icon overIcon)

Here you can find the source of combineIcons(Icon underIcon, Icon overIcon)

Description

Returns an icon that combines the 2 specified icons.

License

Open Source License

Parameter

Parameter Description
underIcon the icon to be drawn first
overIcon the icon to be drawn over top

Return

the combined icon

Declaration

public static Icon combineIcons(Icon underIcon, Icon overIcon) 

Method Source Code

//package com.java2s;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import javax.swing.Icon;
import javax.swing.ImageIcon;

public class Main {
    /**//from  ww  w  . ja va 2  s .c o m
     * Returns an icon that combines the 2 specified icons.
     * One will be drawn over top of the base icon.
     * The resulting icon will be large enough to hold both icons.
     * @param underIcon  the icon to be drawn first
     * @param overIcon   the icon to be drawn over top
     * @return the combined icon
     */
    public static Icon combineIcons(Icon underIcon, Icon overIcon) {
        int newWidth = Math.max(underIcon.getIconWidth(), overIcon.getIconWidth());
        int newHeight = Math.max(underIcon.getIconHeight(), overIcon.getIconHeight());

        BufferedImage combinedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = combinedImage.createGraphics();
        underIcon.paintIcon(null, g2d, 0, 0);
        overIcon.paintIcon(null, g2d, 0, 0);
        g2d.dispose();

        return new ImageIcon(combinedImage);
    }
}

Related

  1. blendIcon(Icon icon, float iconWeight, int rgb, float rgbWeight)
  2. blitBitmap(Graphics g, Icon icon, int x, int y, int w, int h)
  3. buildIcon(final String relativePath, final Class loader)
  4. changeBrightness(Icon icon, float factor)
  5. clearMergedIconsCache()
  6. concatenateIcons(final Icon icon1, final Icon icon2)
  7. createBitmap(Icon icon)
  8. createChannelIcon(Icon ic)
  9. createColourIcon(int colour)