Java Swing Icon getBadgedIcon(Icon icon, Icon badge)

Here you can find the source of getBadgedIcon(Icon icon, Icon badge)

Description

get Badged Icon

License

Open Source License

Declaration

public static Icon getBadgedIcon(Icon icon, Icon badge) 

Method Source Code


//package com.java2s;
/*/* ww  w  . j a  v a 2s  .  co m*/
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

import java.awt.*;

import javax.swing.*;

public class Main {
    public static Icon getBadgedIcon(Icon icon, Icon badge) {
        int sHeight = badge.getIconHeight();
        int sWidth = badge.getIconWidth();

        return getBadgedIcon(icon, badge, sWidth / 2, sHeight / 2);
    }

    public static Icon getBadgedIcon(final Icon icon, final Icon badge, int xOffset, int yOffset) {

        // Calculate once
        final int sHeight = badge.getIconHeight();
        final int sWidth = badge.getIconWidth();
        final int height = icon.getIconHeight() + yOffset;
        final int width = icon.getIconWidth() + xOffset;

        return new Icon() {
            public int getIconHeight() {
                return height;
            }

            public int getIconWidth() {
                return width;
            }

            public void paintIcon(Component c, Graphics g, int x, int y) {
                icon.paintIcon(c, g, x, y);
                badge.paintIcon(c, g, x + width - sWidth, y + height - sHeight);
            }
        };
    }
}

Related

  1. createTransparentIcon(final int width, final int height)
  2. createTransparentIcon(int width)
  3. darken(Icon icon)
  4. emptyIcon(final int width, final int height)
  5. getApplicationIcons()
  6. getbtnIcon(String iconpath)
  7. getbtniconpresspress(String Iconpath1, String pressIconpath2, String pressIconpath3)
  8. getClosestIcon(Collection icons, int height)
  9. getDefaultIcon()