Thursday, March 19, 2009

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:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey(Read More about him) .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP