Java Swing Tutorial - 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;
/* www .j  a  va2s  . 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);
  }
}