Java JButton Create createButton(String aText, String aTooltip, ActionListener aListener)

Here you can find the source of createButton(String aText, String aTooltip, ActionListener aListener)

Description

Creates a new button with manageable width.

License

Open Source License

Parameter

Parameter Description
aText Text of the button.
aTooltip Tooltip text for the button. Set this to <code>null</code> if no tooltip is to be displayed.
aListener Button click's listener.

Return

Newly created instance of JButton.

Declaration

public static JButton createButton(String aText, String aTooltip, ActionListener aListener) 

Method Source Code

//package com.java2s;
/*/*from   ww w.j  av a2  s  . co m*/
 * Copyright (c) 2006, 2007, 2008, 2010, Max Planck Institute for Informatics, Saarbruecken, Germany.
 *
 * This file is part of NetworkAnalyzer.
 * 
 * NetworkAnalyzer is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 * 
 * NetworkAnalyzer 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 Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with NetworkAnalyzer. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.JButton;

public class Main {
    /**
     * Creates a new button with manageable width.
     * 
     * @param aText
     *            Text of the button.
     * @param aTooltip
     *            Tooltip text for the button. Set this to <code>null</code> if no tooltip is to be displayed.
     * @param aListener
     *            Button click's listener.
     * @return Newly created instance of <code>JButton</code>.
     */
    public static JButton createButton(String aText, String aTooltip, ActionListener aListener) {
        JButton button = new JButton(aText);
        button.setToolTipText(aTooltip);
        button.addActionListener(aListener);
        button.setMaximumSize(new Dimension(Short.MAX_VALUE, button.getHeight()));
        return button;
    }
}

Related

  1. createButton(Action action)
  2. createButton(char mnemonic, Action action, Icon icon)
  3. CreateButton(final String name, final String text, final ImageIcon icon, final JPanel panel)
  4. createButton(Icon icon, String tooltip, String ac)
  5. createButton(ImageIcon icon, String text)
  6. createButton(String name, ActionListener listener)
  7. createButton(String name, int x, int y, int width, int height, ImageIcon imageIcon)
  8. createButton(String text, boolean parse)
  9. createButton(String text, String icon)