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

AbstractButtonmakeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)
Make a "buttcon" = button with an Icon
AbstractButton butt;
if (is_toggle) {
    butt = new JToggleButton();
} else {
    butt = new JButton();
if (debug) {
    System.out.println("   makeButtcon" + icon + " " + rollover + " " + tooltip + " " + is_toggle);
...
IconmergeComponentAndIcon(JComponent component, Icon icon)
Draw the component at the left of the provided icon
Dimension compSize = component.getPreferredSize();
component.setSize(compSize);
int compWidth = compSize.width;
int compHeight = compSize.height;
int iconY = 0;
if (icon != null) {
    compWidth += icon.getIconWidth();
    if (compHeight > icon.getIconHeight()) {
...
ImageIconmergeIcons(Icon i1, Icon i2, int offsetRechtsOben)
merge Icons
Image image1 = ((ImageIcon) i1).getImage();
Image image2 = ((ImageIcon) i2).getImage();
Image image = new BufferedImage(i1.getIconWidth(), i1.getIconWidth(), BufferedImage.TRANSLUCENT);
Graphics g = image.getGraphics();
g.drawImage(image1, 0, 0, null);
g.drawImage(image2, i1.getIconWidth() - i2.getIconWidth() - offsetRechtsOben, offsetRechtsOben, null);
g.dispose();
return new ImageIcon(image);
...
Iconreescala(Icon ic, int maxW, int maxH)
reescala
if (ic == null) {
    return null;
if (ic.getIconHeight() == maxH && ic.getIconWidth() == maxW) {
    return ic;
BufferedImage bi = new BufferedImage(ic.getIconHeight(), ic.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
...
Iconresize(Icon icon, int width, int height)
Resizes an icon.
if (icon == null) {
    return icon;
if ((height <= 0 || height == icon.getIconHeight()) && (width <= 0 || width == icon.getIconWidth())) {
    return icon;
Image image = iconToImage(icon);
if (height <= 0) {
...
IconscaleDown(Icon icon, int maxWidth, int maxHeight)
scale Down
int w = icon.getIconWidth();
int h = icon.getIconHeight();
if (maxWidth > w && maxHeight > h) {
    return icon;
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) image.getGraphics();
icon.paintIcon(null, g2d, 0, 0);
...
voidsetComponentTabIcon(Component component, Icon icon)
set Component Tab Icon
Component parent = component.getParent();
while (parent != null) {
    if (parent instanceof JTabbedPane) {
        JTabbedPane tabbedPane = (JTabbedPane) parent;
        int index = tabbedPane.indexOfComponent(component);
        tabbedPane.setIconAt(index, icon);
        break;
    component = parent;
    parent = parent.getParent();
voidsizeToIcon(JComponent component, Icon icon)
Sizes a component based on the size of the provided icon.
if (icon != null) {
    int height = icon.getIconHeight();
    int width = icon.getIconWidth();
    Dimension d = new Dimension(width, height);
    component.setPreferredSize(d);