Here you can find the source of createSmallButton(Icon icon, String tooltip, ActionListener listener)
public static JButton createSmallButton(Icon icon, String tooltip, ActionListener listener)
//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; } }