• 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

setting keyboard navigation (shortcut keys) to the Buttons

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to set hot keys / shortcut keys /mnemonics whatever u call...to the objects of class Button.
I found an option to set Mnemonics to an instance of JButton but plz let me know a way to create shrt keys to a plain java.awt.Button class without using any event handling mechanisms or so ..
Tell me is it possible first of all without using any event handling mechanisms?

thanks in advance.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AWT's Button doesn't have a method for this, the only solution I can think of is adding a keylistener to the button.

Button btn = new Button("Press Me");
btn.addKeyListener(myKeyListener);
 
raj lakshmi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi raj thank you for your response...can u plz detail of how to handle the shortcut keys after adding this listener.
hope I am nt bugging fr a minute thing!! very new to awt
 
Shan Accent
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create the myKeyListener class and implement KeyListener interface then override the following interface methods.

public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyPPressed");
//Get the key code and process what key you want.
}

public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}

public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}


Note:
It works only when it focused on the particular button or key listener component.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here's one way



but the better method (apparently) is to use KeyBindings
http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
 
raj lakshmi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks fr ur replies...I could complete the task with the tips given by you people.

thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic