Link to home
Start Free TrialLog in
Avatar of visa
visa

asked on

Event/Focus/Key Listener Problem.

I am trying to write a java GUI application where one of the screen is to have several buttons.  I want to make it where I can simply type in (using the keyboard) a specified key and have the focus transfer from one key to the specified key.  For example, if key "A" has the focus and I want key "C" to gain the focus from key "A", I just want to press key C on the keyboard and not use the mouse.  This application is written for a power user I guess.
I can make the focus traverse the button list so that's not what I want, I want the focus to pass button B if its presently on button A and I type C on the keyboard.
Avatar of visa
visa

ASKER

Edited text of question
Write a focus manager class which maintains a list of buttons (vector) whose focus need to be
managed. This focus manager class implements the KeyListener interface. It registers itself as a valid keylistener for all the buttons in the list. Also, register this focusmanager class as key listener to the  parent of all the buttons When a key event occurs on a button, the focus manager class callback gets called. In this keyPress method, send the focus to appropriate component using requestFocus method of that component (button).
ASKER CERTIFIED SOLUTION
Avatar of niges
niges

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
D'oh please reject that answer, I meant it as a comment not answer.

--Nige
Avatar of visa

ASKER

I understand the solution for the most part, but I do not understand fully the part about the "parent" of the buttons.  I don't exactly understand what this "parent" is.  Please clarify this to me.  Thanks.

Visa