I thought I would be able to use:
Component focusOwner = window.getFocusOwner();
anotherComponent.requestFocusInWindow();
// do some work
focusOwner.requestFocusInWindow();
but seems like it is not that straightforward. I'm not expert and
I'm surely missing something.
I'm trying the following: In order to keep the GUI from "freezing"
I'm starting a job in a dedicated thread, but I want to block any
input till the job is done. So I register a mouse and key listener
(which consume all the input events) to the glass pane of my frame
and trigger its visibility. Seems o.k. but it doesn't remove the
focus from text fields and I'm not sure if there are other things
I'm missing.
I've put a self contained test case here:
http://www.geocities.com/stanio/test/FocusTest.java
Try both: focusing the button and the text area before invoking the
"Test" menu item. Note I'm aiming to achieve behavior just like when
one selects an item from the menu - the focus is lost, but right
after "exiting" the menu the focus is returned where it was.

Signature
Stanimir
Stanimir Stamenkov - 17 Dec 2004 08:19 GMT
/Stanimir Stamenkov/:
> I thought I would be able to use:
>
[quoted text clipped - 5 lines]
> but seems like it is not that straightforward. I'm not expert and I'm
> surely missing something.
O.k. The first thing I've missed I should make the glass pane
visible prior invoking 'requestFocusInWindow()' but then after I
hide the glass pane, the focus is returned to the text area always.
I've noticed I always get the JRootPane of my window as result from
'window.getFocusOwner()' so I can't really get how can I restore the
focus to the component previously owning it.

Signature
Stanimir
Stanimir Stamenkov - 17 Dec 2004 10:30 GMT
/Stanimir Stamenkov/:
> /Stanimir Stamenkov/:
>
[quoted text clipped - 14 lines]
> 'window.getFocusOwner()' so I can't really get how can I restore the
> focus to the component previously owning it.
I think I've got it. I don't need 'KeyListener' but a
'FocusListener' to register to my glass pane, so I could stop any
actions trying to steal the focus from it and even to register the
original focus owner to which to return the focus after I hide the
glass pane. I've put a revised example, which seems to work as I've
intended, here:
http://www.geocities.com/stanio/test/NewFocusTest.java

Signature
Stanimir
Andrei Kouznetsov - 17 Dec 2004 19:36 GMT
> I'm trying the following: In order to keep the GUI from "freezing" I'm
> starting a job in a dedicated thread, but I want to block any input till
> the job is done. So I register a mouse and key listener (which consume all
> the input events) to the glass pane of my frame and trigger its
> visibility. Seems o.k. but it doesn't remove the focus from text fields
> and I'm not sure if there are other things I'm missing.
see http://www.javaworld.com/javaworld/javatips/jw-javatip89.html

Signature
Andrei Kouznetsov
http://uio.dev.java.net Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Stanimir Stamenkov - 17 Dec 2004 20:30 GMT
/Andrei Kouznetsov/:
> see http://www.javaworld.com/javaworld/javatips/jw-javatip89.html
Hm, I've taken a look and it seems interesting, but I think the
solution I've come up at the end of my monologue branch of this
thread :-) is much simpler (at least for my specific purpose).
Thank you.

Signature
Stanimir