• 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

Controlling Button Focus with Arrow Keys

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a 3x3 grid of buttons and I'd like to let the user control which button has focus by using the arrow keys on the keyboard.
Is there an easy way to do this?
Needs to be done using AWT.
Thanks!
Drew
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm making some progress with this, but I think I need to know how get the currently focused component in order to have any chance of doing this.
How do you determine this?
Drew
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to keep track of focus by attaching a FocusListener to each of your buttons and use that to see which button currently has the focus.
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I used the FocusListener and I'm receiving FocusGained and FocusLost events, but how do I know which button is triggering this?
There doesn't seem to be a method that returns the component that fired the FocusEvent e in the method below?
public void focusGained(FocusEvent e){}
Regards,
Drew
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:


OK thanks, that works for getting a reference to the Button that fired the event.
Thing is, I've got these buttons in a multi dimensional array.
Is there a method that will return the buttons index position in the array once I've got a reference to it?
Thanks,
Drew
 
reply
    Bookmark Topic Watch Topic
  • New Topic