Java JButton Create createButton(String text, boolean parse)

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

Description

Creates a new button with the given text.

License

Open Source License

Parameter

Parameter Description
text DOCUMENT ME!
parse DOCUMENT ME!

Return

new button with the given text.

Declaration

public static JButton createButton(String text, boolean parse) 

Method Source Code

//package com.java2s;
/*/*w ww  .ja va  2s .  com*/
 * Copyright (c) 2001-2002, Marco Hunsicker. All rights reserved.
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 */

import javax.swing.AbstractButton;
import javax.swing.JButton;

public class Main {
    /**
     * Creates a new button with the given text.
     *
     * @param text DOCUMENT ME!
     * @param parse DOCUMENT ME!
     *
     * @return new button with the given text.
     *
     * @since 1.0b9
     */
    public static JButton createButton(String text, boolean parse) {
        JButton button = new JButton();

        if (parse) {
            setMenuText(button, text, true);
        } else {
            button.setText(text);
        }

        return button;
    }

    /**
     * Creates a new button with the given text.
     *
     * @param text DOCUMENT ME!
     *
     * @return new button with the given text.
     *
     * @since 1.0b9
     */
    public static JButton createButton(String text) {
        return createButton(text, true);
    }

    /**
     * DOCUMENT ME!
     *
     * @param item DOCUMENT ME!
     * @param text DOCUMENT ME!
     * @param useMnemonic DOCUMENT ME!
     */
    public static void setMenuText(AbstractButton item, String text, boolean useMnemonic) {
        int i = text.indexOf('&');

        if (i < 0) {
            item.setText(text);
        } else {
            item.setText(text.substring(0, i) + text.substring(i + 1));

            if (useMnemonic) {
                item.setMnemonic(text.charAt(i + 1));
            }
        }
    }
}

Related

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