Example usage for javax.swing AbstractButton setDisplayedMnemonicIndex

List of usage examples for javax.swing AbstractButton setDisplayedMnemonicIndex

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "the index into the String to draw the keyboard character mnemonic at")
public void setDisplayedMnemonicIndex(int index) throws IllegalArgumentException 

Source Link

Document

Provides a hint to the look and feel as to which character in the text should be decorated to represent the mnemonic.

Usage

From source file:Main.java

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

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);//from  w ww.  ja v  a 2  s  .  co  m
    f.pack();
    f.setVisible(true);
}

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

/**
 * @noinspection ALL/*from w  w w. j  ava  2 s .  com*/
 */
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: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.
 *//*from  w  w w  . ja v  a 2 s.  c om*/
public void configureButton(AbstractButton button) {
    Assert.notNull(button);
    button.setText(this.text);
    button.setMnemonic(getMnemonic());
    button.setDisplayedMnemonicIndex(getMnemonicIndex());
}