Java JButton Create createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)

Here you can find the source of createToggleButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action)

Description

create Toggle Button

License

Open Source License

Declaration

public static JToggleButton createToggleButton(ImageIcon icon, int dimension, String tooltipText,
            java.awt.event.ActionListener action) 

Method Source Code

//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;
    }
}

Related

  1. createSimpleTextButton(String caption, Action action)
  2. createSmallButton()
  3. createSmallButton(Icon icon, String tooltip, ActionListener listener)
  4. createSquareButton(String text, int size)
  5. createStandartButton(String name)
  6. createToolBarButton(Action action)
  7. createToolBarButton(String text, Icon icon)
  8. createToolBarToggleButton(ImageIcon ic, String toolTip, ActionListener al)
  9. createTransparentButton(Action action, boolean withText)