• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic