Java JButton Create createIconButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)

Here you can find the source of createIconButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)

Description

create Icon Button

License

Open Source License

Declaration

public static JButton createIconButton(ImageIcon icon, int dimension, String tooltipText,
            java.awt.event.ActionListener action) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Dimension;
import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class Main {
    public static JButton createIconButton(ImageIcon icon, int dimension, String tooltipText,
            java.awt.event.ActionListener action) {
        JButton btn = new JButton();
        btn.setToolTipText(tooltipText);
        btn.setIcon(icon);/*  w  w  w.j av a2 s  .co m*/

        btn.setMaximumSize(new Dimension(dimension, dimension));
        btn.setMinimumSize(new Dimension(dimension, dimension));
        btn.setPreferredSize(new Dimension(dimension, dimension));
        btn.setMargin(new Insets(0, 0, 0, 0));

        if (action != null)
            btn.addActionListener(action);

        return btn;
    }
}

Related

  1. createCustomButton(Action a)
  2. CreateFlatButton()
  3. createGameRadioButton(String answer, int fontSize)
  4. createHyperlinkButton(String text, String tip, ActionListener action)
  5. createIconButton(Class klass, String resource, String fallbackText)
  6. createJButton(Container c, String caption, int x, int y, int width, int height, ActionListener al)
  7. createJButton(final String label, final Font font)
  8. createJButton(String label, Font font)
  9. createJButton(String text, String name, ActionListener a)