Is there a "clean" way to the focus not move from
(or perhaps move back to) a component that is
disabled then enabled?
Example: I have a panel with several buttons. The
focus is on one of the buttons. Pressing the space
bar on the keyboard causes the button with the focus
to depress, which triggers an ActionEvent for the
listener on the button. One thing leads to another,
and the some of the buttons on the panel (including
the pressed button) become disabled. A while later,
an external event occurs that causes the buttons
to enable again. However, the focus has automatically
moved from the disabled button to some other enabled
component. Now the problem is that if the user wants
to just press the space bar on the keyboard to activate
the button again, the focus has moved elsewhere and
some other component will receive the space bar event.
The only way around this so far is to bind a function
key to the button and advise the user to press the
function key instead of the space bar, because the
disabling/enabling action moves the focus to an
unpredictable component. Each button is assigned a
different function key and the user must remember
the assignments. This is not nice for a user interface,
when a user is accustomed to pressing the TAB key to
move the focus to a button, then repeatedly pressing
the space bar to activate the button. (Remember, he
wants to do this one of many buttons on the panel, so
I cannot re-bind the space bar to a particular button.)
I've thought about maybe adding some code somewhere
that would remember that a button had the focus just
before it became disabled, but that won't work in general.
It fails because the focus moves upon disablement to another
button, then subsequently that button becomes disabled
and the focus moves again. When the external event occurs
that causes several buttons to enable, there is apparently
no way to know which of the buttons that about to become
enabled should regain the focus so that the space bar will
correctly activate the button that originally caused the
disablement.
Any suggestions are appreciated.
Andrew Thompson - 21 Jan 2004 16:58 GMT
| Is there a "clean" way to the focus not move from
| (or perhaps move back to) a component that is
| disabled then enabled?
It would seem it is up to the programmer to..
reEnabledButton1.setEnabled(true);
reEnabledButton2.setEnabled(true);
reEnabledButton3.setEnabled(true);
reEnabledButton2.requestFocus();
...
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site