Example usage for javax.swing AbstractButton setMnemonic

List of usage examples for javax.swing AbstractButton setMnemonic

Introduction

In this page you can find the example usage for javax.swing AbstractButton setMnemonic.

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(char mnemonic) 

Source Link

Document

This method is now obsolete, please use setMnemonic(int) to set the mnemonic for a button.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setMnemonic((int) 'P');

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);// ww  w  .j av a2s. co m
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setMnemonic('P');

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*from  ww  w.  j a v  a2 s .  c o  m*/
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void putNemonicKey(AbstractButton button, char mnemonicKey) {
    String text = button.getText();
    if (text.indexOf(mnemonicKey) >= 0) {
        button.setText(getLabelName(text, mnemonicKey, false));
    }//from  w  w  w  . ja v a 2 s .c  om
    button.setMnemonic(mnemonicKey);
}

From source file:Main.java

public static void putNemonicKey(AbstractButton button, int mnemonicKey) {
    String text = button.getText();
    if ('A' <= mnemonicKey && mnemonicKey <= 'Z') {
        button.setText(getLabelName(text, (char) mnemonicKey, false));
    }/*from  w  w w .  ja  va  2s . com*/
    button.setMnemonic(mnemonicKey);
}

From source file:Main.java

/**
 * DOCUMENT ME!/*from ww w  . j av  a  2 s.co  m*/
 *
 * @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));
        }
    }
}

From source file:edu.ku.brc.specify.toycode.UpdatesApp.java

/**
 * Sets a mnemonic on a button./* ww  w  .j av a  2  s.  co  m*/
 * @param btn the button
 * @param mnemonicKey the one char string.
 */
public static void setMnemonic(final AbstractButton btn, final String mnemonic) {
    if (StringUtils.isNotEmpty(mnemonic) && btn != null) {
        btn.setMnemonic(mnemonic.charAt(0));
    }
}

From source file:Main.java

/** 
 * Uses the value returned via the component's getText() method to set a Mnemonic key.
 * The character following the first '&' charcater is used as Mnemonic key,
 * but this only works for characters in the range a..Z
 * If a Mnemonic key is found, the '&' character is removed from the text.
 * @param textComponent//www  . jav a 2s .c o m
 */
public static void setMnemonic(AbstractButton textComponent) {

    String label = textComponent.getText();
    if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) {

        return;
    }
    char ch = label.charAt(label.indexOf('&') + 1);
    if (!Character.isLetter(ch)) {
        return;
    }
    int ke = getKeyEvent(ch);
    if (ke != Integer.MIN_VALUE) {
        label = label.substring(0, label.indexOf('&'))
                + label.substring(label.indexOf('&') + 1, label.length());
        textComponent.setText(label);
        textComponent.setMnemonic(ke);
    }
}

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

/**
 * @noinspection ALL//from   w  w w . j a v a 2  s.  c  o m
 */
private void $$$loadButtonText$$$(AbstractButton component, String text) {
    StringBuffer result = new StringBuffer();
    boolean haveMnemonic = false;
    char mnemonic = '\0';
    int mnemonicIndex = -1;
    for (int i = 0; i < text.length(); i++) {
        if (text.charAt(i) == '&') {
            i++;
            if (i == text.length())
                break;
            if (!haveMnemonic && text.charAt(i) != '&') {
                haveMnemonic = true;
                mnemonic = text.charAt(i);
                mnemonicIndex = result.length();
            }
        }
        result.append(text.charAt(i));
    }
    component.setText(result.toString());
    if (haveMnemonic) {
        component.setMnemonic(mnemonic);
        component.setDisplayedMnemonicIndex(mnemonicIndex);
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Sets a mnemonic on a button./* w  ww  .  j a va 2 s.  co  m*/
 * @param btn the button
 * @param mnemonicKey the one char string.
 */
public static void setLocalizedMnemonic(final AbstractButton btn, final String mnemonicKey) {
    if (StringUtils.isNotEmpty(mnemonicKey)) {
        String mnemonic = getResourceString(mnemonicKey);
        if (btn != null && isNotEmpty(mnemonic)) {
            btn.setMnemonic(getResourceString(mnemonic).charAt(0));
        }
    }
}

From source file:org.springframework.richclient.core.LabelInfo.java

/**
 * Configures the given button with the properties held in this instance. Note that this
 * instance doesn't hold any keystroke accelerator information.
 *
 * @param button The button to be configured.
 *
 * @throws IllegalArgumentException if {@code button} is null.
 *//*  w  ww.  j  a  v a 2s.c om*/
public void configureButton(AbstractButton button) {
    Assert.notNull(button);
    button.setText(this.text);
    button.setMnemonic(getMnemonic());
    button.setDisplayedMnemonicIndex(getMnemonicIndex());
}