Java JButton Settings getIcon(AbstractButton b)

Here you can find the source of getIcon(AbstractButton b)

Description

Returns the current icon for the specified button.

License

Open Source License

Parameter

Parameter Description
b Button.

Return

Icon for the specified button.

Declaration

public static Icon getIcon(AbstractButton b) 

Method Source Code

//package com.java2s;

import javax.swing.*;

public class Main {
    /**//from ww w . j  ava  2s .com
     * Returns the current icon for the specified button. This method is <b>for
     * internal use only</b>.
     * 
     * @param b
     *            Button.
     * @return Icon for the specified button.
     */
    public static Icon getIcon(AbstractButton b) {
        Icon icon = b.getIcon();
        if (icon == null)
            return null;
        ButtonModel model = b.getModel();
        Icon tmpIcon = null;

        if (icon != null) {
            if (!model.isEnabled()) {
                if (model.isSelected()) {
                    tmpIcon = b.getDisabledSelectedIcon();
                } else {
                    tmpIcon = b.getDisabledIcon();
                }
            } else if (model.isPressed() && model.isArmed()) {
                tmpIcon = b.getPressedIcon();
            } else if (b.isRolloverEnabled() && model.isRollover()) {
                if (model.isSelected()) {
                    tmpIcon = b.getRolloverSelectedIcon();
                } else {
                    tmpIcon = b.getRolloverIcon();
                }
            } else if (model.isSelected()) {
                tmpIcon = b.getSelectedIcon();
            }

            if (tmpIcon != null) {
                icon = tmpIcon;
            }
        }
        return icon;
    }
}

Related

  1. getButtonSelectColor()
  2. getButtonSelectedInt(ButtonGroup buttonGroup)
  3. getButtonSelectedString(ButtonGroup buttonGroup)
  4. getDefaultFatButtonMargin()
  5. getHudControlShadowSize(AbstractButton button)
  6. getListenedButtonsFor(Container c)
  7. getMonospaceButton(final String text, final int size)
  8. getPreferredButtonSize(AbstractButton b, int textIconGap)
  9. getPreferredButtonSize(AbstractButton b, int textIconGap)