When a JFrame is dragged (on Solaris; reportedly not on NT) the JFrame grabs the
focus from its rightful owner such that afterwards, until the user clicks somewhere to refocus, jframe.getFocusOwner() will return the JFrame.
Comments
EVALUATION
This bug only occurs on Solaris. When I first started looking at it, I concluded that this was an awt bug. However, the following non-swing program does not exhibit the bug, so the suspect is again swing:
class TimerThread extends Thread {
public void run() {
while(true) {
System.out.println( "fRootW.getFocusOwner() is "
+ FocusBug.globalFrame.getFocusOwner() );
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
}
}
public class FocusBug {
private Frame fRootW;
private TextArea jTextArea;
static Frame globalFrame;
public FocusBug() {
fRootW = new Frame();
globalFrame = fRootW;
jTextArea = new TextArea();
fRootW.setLayout( new BorderLayout() );
fRootW.setBounds( new Rectangle( 0, 0, 200, 200 ) );
fRootW.add( jTextArea );
fRootW.show();
TimerThread t = new TimerThread();
t.start();
}
public static void main( String[] argv ) {
new FocusBug();
}
}
hania.gajewska@Eng 1998-05-22
I am marking this as Evaluated in the new sense of the word: that is, I know it's a bug and I can reproduce it. I don't know what causes it, though.
hania.gajewska@Eng 1998-06-02
This was, after all, an awt bug. The problem is that the focus events that got generated by awt when the user drags the frame come accross as permanent, rather than temporary, focus changes. As a result of the permanent focus change, the focus won't be restored to the subcomponent which had focus before the focus change -- that's just the intended semantics of a permanent focus change. So the fix needed is in the motif code that generates awt focus events.
I am marking this as a duplicate of the appropriate awt bug.
hania.gajewska@Eng 1999-02-08
08-02-1999
WORK AROUND
Click in the text field or text area you want to type in.
The above workaround 'works' only from a user's perspective. From the
perspective of a programmer, who can't count on the user's timely intervention,
the workaround is much more complex. In summary, it involves keeping track of
what Component last had focus and of running a Timer to check who next gets focus, and then, if the next focus onwer is a JFrame, of restoring the focus to
the last legitimate owner.
eric.house@eng 1998-05-26