Set Mnemonic Key for JCheckBox in Java
Description
The following code shows how to set Mnemonic Key for JCheckBox.
Example
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
// w ww . ja v a 2s.co m
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("JCheckBox Test");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JCheckBox ac = new JCheckBox("A/C");
ac.setSelected(true);
ac.setMnemonic(KeyEvent.VK_A);
frame.add(ac);
frame.pack();
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »