Here you can find the source of createButton(String text, String icon)
Parameter | Description |
---|---|
text | String Text to put inside the button |
icon | String Image embedded into the button |
public static JButton createButton(String text, String icon)
//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; } }