Java Swing Icon concatenateIcons(final Icon icon1, final Icon icon2)

Here you can find the source of concatenateIcons(final Icon icon1, final Icon icon2)

Description

Concatenates 2 icons next to each other (in 1 row).

License

Apache License

Parameter

Parameter Description
icon1 first icon to be concatenated (this will be on the left side)
icon2 second icon to be concatenated (this will be on the right side)

Return

an icon that is the result of the concatenation of the 2 specified icons

Declaration

public static Icon concatenateIcons(final Icon icon1, final Icon icon2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.awt.Component;

import java.awt.Graphics;

import javax.swing.Icon;

public class Main {
    /**/*from w w w.  j av a2  s . c om*/
     * Concatenates 2 icons next to each other (in 1 row).
     * @param icon1 first icon to be concatenated (this will be on the left side)
     * @param icon2 second icon to be concatenated (this will be on the right side)
     * @return an icon that is the result of the concatenation of the 2 specified icons
     */
    public static Icon concatenateIcons(final Icon icon1, final Icon icon2) {
        return new Icon() {
            @Override
            public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
                icon1.paintIcon(c, g, x, y);
                icon2.paintIcon(c, g, x + icon1.getIconWidth(), y);
            }

            @Override
            public int getIconWidth() {
                return icon1.getIconWidth() + icon2.getIconWidth();
            }

            @Override
            public int getIconHeight() {
                return Math.max(icon1.getIconHeight(), icon2.getIconHeight());
            }
        };
    }
}

Related

  1. blitBitmap(Graphics g, Icon icon, int x, int y, int w, int h)
  2. buildIcon(final String relativePath, final Class loader)
  3. changeBrightness(Icon icon, float factor)
  4. clearMergedIconsCache()
  5. combineIcons(Icon underIcon, Icon overIcon)
  6. createBitmap(Icon icon)
  7. createChannelIcon(Icon ic)
  8. createColourIcon(int colour)
  9. createGrayIcon(Icon icon)