Here you can find the source of combineIcons(Icon underIcon, Icon overIcon)
Parameter | Description |
---|---|
underIcon | the icon to be drawn first |
overIcon | the icon to be drawn over top |
public static Icon combineIcons(Icon underIcon, Icon overIcon)
//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); } }