Java JButton Create createButton(String text, String icon)

Here you can find the source of createButton(String text, String icon)

Description

Create a button with a pre-defined look-and-feel

License

Open Source License

Parameter

Parameter Description
text String Text to put inside the button
icon String Image embedded into the button

Return

JButton initialised

Declaration

public static JButton createButton(String text, String icon) 

Method Source Code

//package com.java2s;
/**/*from   w  w w  . j  av a  2s .  com*/
 * IMAS base code for the practical work. 
 * Copyright (C) 2014 DEIM - URV
 *
 * This program 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.
 *
 * This program 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
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class Main {
    public static Color buttonGgColor = new Color(240, 210, 160);
    public static Font buttonFont = new Font("Arial", 0, 11);
    public static Color buttonTextColor = Color.BLACK;

    /**
     * Create a button with a pre-defined look-and-feel
     *
     * @param text String Text to put inside the button
     * @param icon String Image embedded into the button
     * @return JButton initialised
     */
    public static JButton createButton(String text, String icon) {
        ImageIcon iconRefresh = new ImageIcon(icon);
        JButton jButton = new JButton(iconRefresh);
        jButton.setBorderPainted(false);
        jButton.setBackground(buttonGgColor);
        jButton.setForeground(buttonTextColor);
        jButton.setFont(buttonFont);
        jButton.setText(text);
        jButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        jButton.setEnabled(true);
        return jButton;
    }
}

Related

  1. createButton(ImageIcon icon, String text)
  2. createButton(String aText, String aTooltip, ActionListener aListener)
  3. createButton(String name, ActionListener listener)
  4. createButton(String name, int x, int y, int width, int height, ImageIcon imageIcon)
  5. createButton(String text, boolean parse)
  6. createButton16(final ImageIcon icon)
  7. createButtonFooter(JButton ok, JButton cancel)
  8. createButtonGroup(javax.swing.AbstractButton... buttons)
  9. createButtonPanel()