Java JButton Settings creaStyledButton(int style)

Here you can find the source of creaStyledButton(int style)

Description

Returns a styled JButton.

License

Open Source License

Parameter

Parameter Description
style button type

Return

a styled button

Declaration

public static JButton creaStyledButton(int style) 

Method Source Code

//package com.java2s;
/*//from   ww  w.  j  a  v a 2  s  .c  om
 The GUFF - The GNU Ultimate Framework Facility
 Copyright (C) Simeosoft di Carlo Simeone
       
 This library 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 2.1 of the License, or (at your option) any later version.
    
 This library 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 this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   
 */

import javax.swing.*;
import java.awt.*;

import javax.swing.border.*;

public class Main {
    public final static int STYLE_EDIT = 0;
    public final static int STYLE_OK = 1;
    public final static int STYLE_CANCEL = 2;
    public final static int STYLE_INSBEFOREROW = 16;
    public final static int STYLE_INSAFTERROW = 17;
    public final static int STYLE_DELETEROW = 18;
    public final static int STYLE_CLONEBEFOREROW = 19;
    public final static int STYLE_CLONEAFTERROW = 20;
    public final static int STYLE_DEFAULTROWS = 21;
    public static Icon ICON_INSBEFOREROW = null;
    public static Icon ICON_INSAFTERROW = null;
    public static Icon ICON_DELETEROW = null;
    public static Icon ICON_CLONEBEFOREROW = null;
    public static Icon ICON_CLONEAFTERROW = null;
    public static Icon ICON_DEFAULTROWS = null;

    /**
     * Returns a styled JButton.
     *
     * @param style button type
     * @return a styled button
     */
    public static JButton creaStyledButton(int style) {
        JButton jb = new JButton();
        jb.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        jb.setMargin(new Insets(0, 5, 1, 5));
        switch (style) {
        case STYLE_EDIT: {
            jb.setText("edit");
            jb.setToolTipText("edit");
            jb.setPreferredSize(new Dimension(60, 30));
            return jb;
        }
        case STYLE_OK: {
            jb.setText("ok");
            jb.setToolTipText("confirm changes");
            jb.setPreferredSize(new Dimension(60, 30));
            return jb;
        }
        case STYLE_CANCEL: {
            jb.setText("cancel");
            jb.setToolTipText("discard changes");
            jb.setPreferredSize(new Dimension(60, 30));
            return jb;
        }
        case STYLE_INSBEFOREROW: {
            jb.setIcon(ICON_INSBEFOREROW);
            jb.setToolTipText("insert row before");
            jb.setName("INSBEFOREROW");
            return jb;
        }
        case STYLE_INSAFTERROW: {
            jb.setIcon(ICON_INSAFTERROW);
            jb.setToolTipText("insert row after");
            jb.setName("INSAFTERROW");
            return jb;
        }
        case STYLE_DELETEROW: {
            jb.setIcon(ICON_DELETEROW);
            jb.setToolTipText("delete row");
            jb.setName("DELETEROW");
            return jb;
        }
        case STYLE_CLONEBEFOREROW: {
            jb.setIcon(ICON_CLONEBEFOREROW);
            jb.setToolTipText("clone row before");
            jb.setName("CLONEBEFOREROW");
            return jb;
        }
        case STYLE_CLONEAFTERROW: {
            jb.setIcon(ICON_CLONEAFTERROW);
            jb.setToolTipText("clone row after");
            jb.setName("CLONEAFTERROW");
            return jb;
        }
        case STYLE_DEFAULTROWS: {
            jb.setIcon(ICON_DEFAULTROWS);
            jb.setToolTipText("set default values");
            jb.setName("DEFAULTROWS");
            return jb;
        }
        default: {
            return null;
        }
        }
    }
}

Related

  1. buttonGroup(JToggleButton b1, JToggleButton b2)
  2. clickButton(final Window window, final String buttonText)
  3. configureOKAndCancelButtons(JPanel panel, Action ok, Action cancel)
  4. configureTextAndMnemonic(AbstractButton button, String text)
  5. confirm(Component comp, String title, String message, int buttons, int type)
  6. customize(AbstractButton btn)
  7. decoratedToSimpleButton(final T button)
  8. doClick(final AbstractButton button)
  9. doHover(boolean b, AbstractButton... btns)