Java AbstractButton .setMnemonic (char mnemonic)

Syntax

AbstractButton.setMnemonic(char mnemonic) has the following syntax.

public void setMnemonic(char mnemonic)

Example

In the following code shows how to use AbstractButton.setMnemonic(char mnemonic) method.


import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
/*from  w w w .  ja v a 2s  . co m*/
public class Main {
  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);
    f.pack();
    f.setVisible(true);
  }
}