Here you can find the source of createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)
public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)
//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; }// w w w .jav a 2s . c o m 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; } }