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

ImageIconcreateTransparentIcon(int width)
create Transparent Icon
final Image image = new BufferedImage(width, width, BufferedImage.TYPE_4BYTE_ABGR);
return new ImageIcon(image);
Icondarken(Icon icon)
Returns a slightly darker version of the icon.
BufferedImage img = getBufferedImageFromIcon(icon);
if (img == null)
    return icon;
BufferedImageOp op = new RescaleOp(0.75f, 0, null);
return new ImageIcon(op.filter(img, null));
IconemptyIcon(final int width, final int height)
Returns an icon with a given size and no content.
return new Icon() {
    public int getIconWidth() {
        return width;
    public int getIconHeight() {
        return height;
    public void paintIcon(Component c, Graphics g, int x, int y) {
...
ListgetApplicationIcons()
get Application Icons
if (tnicon == null) {
    tnicon = new ArrayList<Image>();
    tnicon.add(
            new ImageIcon(ClassLoader.getSystemClassLoader().getResource("tn5250j-16x16.png")).getImage());
    tnicon.add(
            new ImageIcon(ClassLoader.getSystemClassLoader().getResource("tn5250j-32x32.png")).getImage());
    tnicon.add(
            new ImageIcon(ClassLoader.getSystemClassLoader().getResource("tn5250j-48x48.png")).getImage());
...
IcongetBadgedIcon(Icon icon, Icon badge)
get Badged Icon
int sHeight = badge.getIconHeight();
int sWidth = badge.getIconWidth();
return getBadgedIcon(icon, badge, sWidth / 2, sHeight / 2);
JButtongetbtnIcon(String iconpath)
getbtn Icon
JButton button = new JButton();
button.setIcon(new ImageIcon(iconpath));
button.setBorder(null);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
return button;
JButtongetbtniconpresspress(String Iconpath1, String pressIconpath2, String pressIconpath3)
getbtniconpresspress
JButton button = new JButton();
button.setIcon(new ImageIcon(Iconpath1));
button.setPressedIcon(new ImageIcon(pressIconpath2));
button.setPressedIcon(new ImageIcon(pressIconpath3));
button.setBorder(null);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
return button;
...
IgetClosestIcon(Collection icons, int height)
From the given icons, chooses the icon taller than (if available) and closest to the given height.
I icon = null;
if (icons != null) {
    int diff = 0;
    for (I i : icons) {
        int d = i.getIconHeight() - height;
        if (d == 0) {
            return i;
        if (icon == null || (diff < 0 && d > diff) || (diff > 0 && d < diff && d >= 0)) {
            icon = i;
            diff = d;
return icon;
IcongetDefaultIcon()
get Default Icon
BufferedImage bi = new BufferedImage(18, 18, 3);
Graphics2D g2 = bi.createGraphics();
g2.setBackground(Color.red);
g2.clearRect(0, 0, bi.getWidth(), bi.getHeight());
g2.setColor(Color.white);
g2.setStroke(new BasicStroke(2.0F));
GeneralPath x = new GeneralPath();
x.moveTo(0.0F, 0.0F);
...
ImagegetDefaultIcon()
Get the default Icon, which is the icon for a file.
return DEFAULT_ICON;