Java Swing Icon makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)

Here you can find the source of makeButtcon(Icon icon, Icon rollover, String tooltip, boolean is_toggle)

Description

Make a "buttcon" = button with an Icon

License

Open Source License

Parameter

Parameter Description
icon the normal Icon
rollover the rollover Icon
tooltip the tooltip
is_toggle if true, make JToggleButton, else JButton

Return

the buttcon (JButton or JToggleButton)

Declaration

public static AbstractButton makeButtcon(Icon icon, Icon rollover,
        String tooltip, boolean is_toggle) 

Method Source Code

//package com.java2s;
/*/*from   ww  w.j a v a  2s .co m*/
 * $Id: BAMutil.java,v 1.16 2007/07/06 20:45:29 jeffmc Exp $
 *
 * Copyright  1997-2015 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.awt.*;
import javax.swing.*;

public class Main {
    /** _more_ */
    static private boolean debug = false, debugToggle = false;

    /**
     * Make a "buttcon" = button with an Icon
     *  @param icon the normal Icon
     *  @param rollover the rollover Icon
     *  @param tooltip the tooltip
     *  @param is_toggle if true, make JToggleButton, else JButton
     *  @return the buttcon (JButton or JToggleButton)
     */
    public static AbstractButton makeButtcon(Icon icon, Icon rollover,
            String tooltip, boolean is_toggle) {
        AbstractButton butt;
        if (is_toggle) {
            butt = new JToggleButton();
        } else {
            butt = new JButton();
        }

        if (debug) {
            System.out.println("   makeButtcon" + icon + " " + rollover
                    + " " + tooltip + " " + is_toggle);
        }

        if (icon != null) {
            butt.setIcon(icon);
        }
        if (rollover != null) {
            butt.setRolloverIcon(rollover);
            butt.setRolloverSelectedIcon(rollover);
            butt.setPressedIcon(rollover);
            butt.setRolloverEnabled(true);
        }

        butt.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
        if (icon != null) {
            butt.setPreferredSize(new Dimension(icon.getIconHeight() + 2,
                    icon.getIconWidth() + 2));
        } else {
            butt.setPreferredSize(new Dimension(28, 28));
        }

        butt.setMaximumSize(new Dimension(28, 28)); // kludge

        butt.setToolTipText(tooltip);
        butt.setFocusPainted(false);

        return butt;
    }
}

Related

  1. loadIcon(ClassLoader classLoader, String path)
  2. loadIcon(String icon)
  3. loadIcon(String resourceName)
  4. loadIcons(String list, String path, Set ignore, ClassLoader loader)
  5. loadLoadingIcon()
  6. mergeComponentAndIcon(JComponent component, Icon icon)
  7. mergeIcons(Icon i1, Icon i2, int offsetRechtsOben)
  8. reescala(Icon ic, int maxW, int maxH)
  9. resize(Icon icon, int width, int height)