JLabel – Mnemonic


Set Mnemonic

jLabel1.setDisplayedMnemonic('R');

Description:
    Requests focus for the component tied (using "setLabelFor") to this JLabel 
    Assigning the character 'R', for example, requires typing Alt+R to request focus

Reset:
    jLabel1.setDisplayedMnemonic(0);

Note:
    This also resets the Displayed Mnemonic Index

Set Displayed Mnemonic

int index = 1;
if(jLabel1.getText() != null && jLabel1.getText().length() >= (index+1)){
    jLabel1.setDisplayedMnemonicIndex(index);
}

Description:
    Places an underscore on the text character at the index

Reset:
    jLabel1.setDisplayedMnemonicIndex(-1);

Note:
    Doesn't work when JLabel is using HTML text
    The provided index must be less than the text length

Set Label for Component

jLabel1.setLabelFor(jToggleButton5);
Description:
    Set the Component that gets focus when the JLabel's mnemonic is fired.