Java JButton Create buildButton(AbstractButton button, String text, ActionListener handler)

Here you can find the source of buildButton(AbstractButton button, String text, ActionListener handler)

Description

This method builds the specified button according to the specified parameters.

License

Apache License

Parameter

Parameter Description
button The button to build.
text The text displayed on the button.
handler The action listener that monitors the buttons events.

Declaration

public static void buildButton(AbstractButton button, String text, ActionListener handler) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.event.ActionListener;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.Icon;

public class Main {
    /**// w  w w .j a  v  a  2 s . com
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param icon The icon to use.
     * @param handler The action listener that monitors the buttons events.
     * @param command The action command used when the button is clicked.
     * @param tip The tool tip to display.
     */
    public static void buildButton(AbstractButton button, Icon icon, ActionListener handler, String command,
            String tip) {
        buildButton(button, "", icon, handler, command, tip);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param handler The action listener that monitors the buttons events.
     */
    public static void buildButton(AbstractButton button, String text, ActionListener handler) {
        buildButton(button, text, handler, text);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param handler The action listener that monitors the buttons events.
     * @param selected The initial selected state of the button.
     */
    public static void buildButton(AbstractButton button, String text, ActionListener handler, boolean selected) {
        buildButton(button, text, null, handler, text, null, selected, null);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param handler The action listener that monitors the buttons events.
     * @param group The group the button should belong to.
     */
    public static void buildButton(AbstractButton button, String text, ActionListener handler, ButtonGroup group) {
        buildButton(button, text, null, handler, text, group, false, null);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param handler The action listener that monitors the buttons events.
     * @param command The action command used when the button is clicked.
     */
    public static void buildButton(AbstractButton button, String text, ActionListener handler, String command) {
        buildButton(button, text, null, handler, command, null);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param handler The action listener that monitors the buttons events.
     * @param command The action command used when the button is clicked.
     * @param tip The tool tip to display.
     */
    public static void buildButton(AbstractButton button, String text, ActionListener handler, String command,
            String tip) {
        buildButton(button, text, null, handler, command, tip);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param icon The icon to use.
     * @param handler The action listener that monitors the buttons events.
     */
    public static void buildButton(AbstractButton button, String text, Icon icon, ActionListener handler) {
        buildButton(button, text, icon, handler, text, null, false, null);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param icon The icon to use.
     * @param handler The action listener that monitors the buttons events.
     * @param command The action command used when the button is clicked.
     * @param tip The tool tip to display.
     */
    public static void buildButton(AbstractButton button, String text, Icon icon, ActionListener handler,
            String command, String tip) {
        buildButton(button, text, icon, handler, command, null, false, tip);
    }

    /**
     * This method builds the specified button according to the specified
     * parameters.
     *
     * @param button The button to build.
     * @param text The text displayed on the button.
     * @param icon The icon to use.
     * @param handler The action listener that monitors the buttons events.
     * @param command The action command used when the button is clicked.
     * @param group The group the button should belong to.
     * @param selected The initial selected state of the button.
     * @param tip The tool tip to display.
     */
    public static void buildButton(AbstractButton button, String text, Icon icon, ActionListener handler,
            String command, ButtonGroup group, boolean selected, String tip) {
        button.addActionListener(handler);
        button.setActionCommand(command);
        button.setIcon(icon);
        button.setSelected(selected);
        button.setText(text);
        button.setToolTipText(tip);

        if (group != null) {
            group.add(button);
        }
    }
}

Related

  1. button(JPanel panel, String text, char mnemonic, Font font)
  2. button(String name)
  3. createAddRemoveButtonPanel(Action addAction, Icon addIcon, String addToolTip, Action removeAction, Icon removeIcon, String removeToolTip, int axis)
  4. createButton(Action action)