Java JButton Create createSmallButton(Icon icon, String tooltip, ActionListener listener)

Here you can find the source of createSmallButton(Icon icon, String tooltip, ActionListener listener)

Description

create Small Button

License

Apache License

Declaration

public static JButton createSmallButton(Icon icon, String tooltip, ActionListener listener) 

Method Source Code

//package com.java2s;
// License:   Apache Software License (Version 2.0)

import java.awt.Dimension;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Icon;

import javax.swing.JButton;

import javax.swing.SwingConstants;

public class Main {
    public static JButton createSmallButton(Icon icon, String tooltip, ActionListener listener) {
        final JButton btn = new JButton(icon);
        btn.setBorder(BorderFactory.createEmptyBorder());
        final Dimension size = new Dimension(16, 16);
        btn.setMinimumSize(size);//from w w w.j  a v a 2s .  c o m
        btn.setPreferredSize(size);
        btn.setMaximumSize(size);
        btn.setMargin(new Insets(0, 0, 0, 0));
        if (listener != null)
            btn.addActionListener(listener);
        btn.setToolTipText(tooltip);
        btn.setHorizontalAlignment(SwingConstants.CENTER);
        btn.setVerticalAlignment(SwingConstants.CENTER);
        return btn;
    }
}

Related

  1. createRadioButton(String text, int mnemonic, ActionListener listener, boolean selected)
  2. createRadioButtonGrouping(String elements[], String title)
  3. createScreenCaptureButton()
  4. createSimpleTextButton(String caption, Action action)
  5. createSmallButton()
  6. createSquareButton(String text, int size)
  7. createStandartButton(String name)
  8. createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)
  9. createToolBarButton(Action action)