Java tutorial
//package com.java2s; import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.border.EmptyBorder; public class Main { /** * Convenience method for creating buttons with an icon and no text. Wraps * the button in an empty border to give it some space. * @param icon the icon to display * @return a new JButton with the given icon */ public static JButton iconButton(Icon icon) { final JButton result = new JButton(icon); result.setBorder(new EmptyBorder(4, 4, 4, 4)); return result; } /** * Convenience method for creating buttons with an icon and no text. Wraps * the button in an empty border to give it some space. * @param icon the icon to display * @param action the action to perform on click * @return a new JButton with the given icon */ public static JButton iconButton(Icon icon, Action action) { final JButton result = new JButton(action); result.setIcon(icon); result.setBorder(new EmptyBorder(4, 4, 4, 4)); return result; } }