Java JButton Create button(String name)

Here you can find the source of button(String name)

Description

button

License

Open Source License

Declaration

public static JButton button(String name) 

Method Source Code

//package com.java2s;
/*/*from  www.  j av  a 2 s. c  o  m*/
 * Copyright (c) 2012 EDC
 * 
 * This file is part of Stepping Stone.
 * 
 * Stepping Stone is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Stepping Stone is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Stepping Stone.  If not, see <http://www.gnu.org/licenses/gpl.txt>.
 */

import java.awt.event.ActionListener;

import javax.swing.Action;

import javax.swing.JButton;
import javax.swing.JComponent;

public class Main {
    public static JButton button(String name) {
        JButton ret = nameComponent(new JButton(), name);
        ret.setBorderPainted(false);
        // ret.setSelected(false);
        ret.setFocusable(false);
        return ret;
    }

    public static JButton button(String name, ActionListener actionListener) {
        JButton ret = button(name);
        ret.addActionListener(actionListener);
        return ret;
    }

    /**
     * A convenience method to initialize a button with an action
     * 
     * @param name
     * @param action
     * @return
     */
    public static JButton button(String name, Action action) {
        JButton ret = button(name);
        ret.setAction(action);
        return ret;
    }

    public static <C extends JComponent> C nameComponent(C c, String name) {
        c.setName(name);
        return c;
    }
}

Related

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