Java JButton Settings filterMnemonic(final String s, final AbstractButton b)

Here you can find the source of filterMnemonic(final String s, final AbstractButton b)

Description

Filters the mnemonic definition from the given string.

License

Open Source License

Parameter

Parameter Description
s the String that contains the mnemonic definition
b the AbstractButton that should get the mnemonic

Return

the String without the [] of the definition

Declaration

public static String filterMnemonic(final String s, final AbstractButton b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.AbstractButton;

public class Main {
    /**//from www. j  av  a  2  s. c om
     * Filters the mnemonic definition from the given string. If a mnemonic definition ([m]) is found, it will be set to
     * the given AbstractButton.
     * 
     * @param s the String that contains the mnemonic definition
     * @param b the AbstractButton that should get the mnemonic
     * @return the String without the [] of the definition
     */
    public static String filterMnemonic(final String s, final AbstractButton b) {
        if (s != null) {
            String tmpS = s;
            final Matcher m = Pattern.compile("\\[(.)\\]").matcher(tmpS); //$NON-NLS-1$
            if (m.find()) {
                b.setMnemonic(m.group(1).charAt(0));
                tmpS = m.replaceFirst(m.group(1));
            }
            return tmpS;
        }
        return null;
    }
}

Related

  1. doSetTextInEDT(final AbstractButton abstractButton, final String text)
  2. drawActiveButtonBorder(Graphics g, int x, int y, int w, int h)
  3. drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active)
  4. emphasizeButton(AbstractButton btn)
  5. equalizeButtonSizes(JPanel jPanelButtons)
  6. findButton(Container container, String text)
  7. findButtonComponents(Container container, String label)
  8. findDescendantButtonWithText(Container root, String desiredText)
  9. fixButtonUI(AbstractButton button)