Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keys for JButtons

 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank's Joe.
setMnemonik() work well, but setMnemonik() method make available alt + F2 and not F2.
Thank You!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very mutch Nathan!
Very Good Example.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic