Set Mnemonic key for a JButton in Java
Description
The following code shows how to set Mnemonic key for a JButton.
Example
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
//from w w w. ja va2 s .co m
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main {
public static void main(String args[]) {
JButton jbtnA = new JButton("Alpha");
JFrame jfrm = new JFrame();
jfrm.setLayout(new FlowLayout());
jfrm.setSize(300, 300);
jbtnA.setMnemonic(KeyEvent.VK_A);
jfrm.add(jbtnA);
jfrm.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »