Java JButton formatButtonAsLabel(JButton button)

Here you can find the source of formatButtonAsLabel(JButton button)

Description

Formats a JButton as a JLabel.

License

Open Source License

Parameter

Parameter Description
button The button. Some makeup is made to the button, so it will look as a good old JLabel component.

Declaration

public static void formatButtonAsLabel(JButton button) 

Method Source Code

//package com.java2s;
/**//from   ww w . jav a 2  s. c  o  m
 * \cond LICENSE
 * ********************************************************************
 * This is a conditional block for preventing the DoxyGen documentation
 * tool to include this license header within the description of each
 * source code file. If you want to include this block, please define
 * the LICENSE parameter into the provided DoxyFile.
 * ********************************************************************
 *
 * TeXPrinter - A TeX.SX question printer Copyright (c) 2012, Paulo Roberto
 * Massa Cereda All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the project's author nor the names of its contributors
 * may be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * ********************************************************************
 * End of the LICENSE conditional block
 * ********************************************************************
 * \endcond
 *
 * UIUtils.java: This class provides UI helper methods.
 * Last revision: paulo at temperantia 26 Feb 2012 05:12
 */

import java.awt.Insets;

import javax.swing.*;

public class Main {
    /**
     * Formats a JButton as a JLabel. In some cases, I just want the a
     * JButton component to act as a JLabel, so this method does this
     * for me.
     *
     * @param button The button. Some makeup is made to the button, so
     * it will look as a good old JLabel component.
     */
    public static void formatButtonAsLabel(JButton button) {

        // disable focus paint
        button.setFocusPainted(false);

        // redefine margins
        button.setMargin(new Insets(0, 0, 0, 0));

        // disable content area fill
        button.setContentAreaFilled(false);

        // disable border paint
        button.setBorderPainted(false);

        // disable property
        button.setOpaque(false);
    }
}

Related

  1. enterPressesWhenFocused(final JButton button)
  2. equalizeButtons(JButton... buttons)
  3. exit(JButton aButton)
  4. fixButtonWidth(JButton... buttons)
  5. fixToolbarButtonImpl(JButton button)
  6. formatJButton(JButton button, String tooltips)
  7. getButtonNumber(JButton btn)
  8. getScrollStroke(final JButton _jlbl_stroke)
  9. getWFStep(Vector actionButtons, String action)