Setting Mnemonics and Shortcut Keys
Setting a Shrotcut Key(Mnemonic)
A shortcut key is an underlined character you may in labels,buttons,menus etc.These are called as mnemonics.You can select a control by pressing the combination of Alt key and the character.For example if underlined character is 's' then in order to activate control press Alt+s.You can set mnemonic by using setMnemonic(Char ch)
Syntax:-
component.setMnemonic(Char ch);
Exapmle:-
In the Screen shot the mnemonic is set as 'M'.
So this button can be activated by pressing Alt+M.
// memonic.java
import java.awt.*;
import javax.swing.*;
public class mnemonic
{
public static void main(String a[])
{
JFrame frm=new JFrame("Mnemonic Demo");
JPanel panel=new JPanel();
JButton Button=new JButton("Setting Mnemonic");
Button.setMnemonic('M');
panel.add(Button);
frm.getContentPane().add(panel);
frm.setVisible(true);
frm.pack();
}
}


















0 comments:
Post a Comment
Post a Comment