Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import java.awt.Insets; import javax.swing.ImageIcon; import javax.swing.JToggleButton; public class Main { public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action) { JToggleButton btn = createToggleButton(icon, dimension, tooltipText); if (action != null) btn.addActionListener(action); return btn; } public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ItemListener action) { JToggleButton btn = createToggleButton(icon, dimension, tooltipText); if (action != null) btn.addItemListener(action); return btn; } public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText) { JToggleButton btn = new JToggleButton(); btn.setToolTipText(tooltipText); btn.setIcon(icon); 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)); return btn; } }