File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Keys for JButtons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Keys for JButtons" Watch "Keys for JButtons" New topic
Author

Keys for JButtons

Veri Strora
Greenhorn

Joined: Feb 04, 2003
Posts: 27
Hi All!
I have a JButton. How can I assign an "F2" key form the KeyBoard?
(Not "alt + F2" but "F2" only).
Thanks in advance
Veri.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

does setMnemonic() work? If not, I'd think you'd have to make a Component that has focus at all times (i.e. top level frame) a key listener, listen for F2 and send an ActionEvent to the button when that key is hit.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Veri Strora
Greenhorn

Joined: Feb 04, 2003
Posts: 27
Thank's Joe.
setMnemonik() work well, but setMnemonik() method make available alt + F2 and not F2.
Thank You!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Nate,
I bet you have hundreds of these little programs like this from helping people out on javaranch.
Have you ever thought about putting together a type of SWING FAQ and for each Question, you have one of these little programs?
I know we could just search the SWING forum, but knowing a search is returning some code instead of filtering through all the garbage might be nice...
I think it would be neat and very useful. Maybe even write a book. Then you could get that Author status.


GenRocket - Experts at Building Test Data
Veri Strora
Greenhorn

Joined: Feb 04, 2003
Posts: 27
Thank You very mutch Nathan!
Very Good Example.
 
Consider Paul's rocket mass heater.
 
subject: Keys for JButtons