Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Creates a transparent icon

import java.awt.image.BufferedImage; import java.util.Arrays; import javax.swing.Icon; import javax.swing.ImageIcon; public final class ImageUtils {   /**    * Creates a transparent image.  These can be used for aligning menu items.    *    * @param width  the width.    * @param height the height.    * @return the created transparent image.    */   public static BufferedImage createTransparentImage (final int width, final int height)   {     return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);   }   /**    * Creates a transparent icon. The Icon can be used for aligning menu items.    *    * @param width  the width of the new icon    * @param height the height of the new icon    * @return the created transparent icon.    */   public static Icon createTransparentIcon (final int width, final int height)   {     return new ImageIcon(createTransparentImage(width, height));   } }