• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add a shortkey to Menu

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends

I m new to Swings. This is my code written below: -

import javax.swing.*;
class menushortkey
{
void simplemenu()
{
JFrame frame = new JFrame();
JMenuBar menubar = new JMenuBar();
JMenu menu1 = new JMenu("my menu");
JMenuItem item1 = new JMenuItem("HIDE");
JMenuItem item2 = new JMenuItem("SHOW");
menu1.add(item1);
menu1.add(item2);
menubar.add(menu1);
frame.setJMenuBar(menubar);
frame.setVisible(true);
frame.setSize(500,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
menushortkey sh = new menushortkey();
sh.simplemenu();
}
}
Now i want to open "My Menu" with the help of alt+m(Keys). Plzz help me to do this.

THkx in advance.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
menu1.setMnemonic('m');
 
Karan Galhotra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankx Michael
 
Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic