Component Focus

D

Daniel Pitts

Jason said:
Is there a way to track component focus across an entire GUI? What I
am trying to do is keep toolbars updated (by updating their
corresponding actions) depending on what component is currently in
focus.

So...


MainView - this is parent view that holds all project and
propertyviews for my application. MainView contains a method called
"updateActions" which, when called, turns actions on and off depending
on the current status of the application.

What I'd like to have happen is that, when any focus change occurs,
the updateActions method is called. Everything I've tried so far is
not accomplishing this. Any insight provided would be much
appreciated.


Thanks
Has everything you've tried included adding a focus listener on all your
components?
 
J

Jason Cavett

Is there a way to track component focus across an entire GUI? What I
am trying to do is keep toolbars updated (by updating their
corresponding actions) depending on what component is currently in
focus.

So...


MainView - this is parent view that holds all project and
propertyviews for my application. MainView contains a method called
"updateActions" which, when called, turns actions on and off depending
on the current status of the application.

What I'd like to have happen is that, when any focus change occurs,
the updateActions method is called. Everything I've tried so far is
not accomplishing this. Any insight provided would be much
appreciated.


Thanks
 
J

Jason Cavett

Has everything you've tried included adding a focus listener on all your
components?

My apologies for not adding that, no I haven't tried that method, but
only due to the fact that it would be extremely time consuming for
something that doesn't give a lot of return. Also, considering the
size of the application (incl. all JTextFields, JTrees, Panels, etc)
this is something I'd like to do as a last resort.

Basically, I'm wondering if there's an easier way that I hadn't
thought of. If not, I can use the method you described or just not
worry about it at all.

Thanks, though.
 
D

Daniel Pitts

Jason said:
My apologies for not adding that, no I haven't tried that method, but
only due to the fact that it would be extremely time consuming for
something that doesn't give a lot of return. Also, considering the
size of the application (incl. all JTextFields, JTrees, Panels, etc)
this is something I'd like to do as a last resort.

Basically, I'm wondering if there's an easier way that I hadn't
thought of. If not, I can use the method you described or just not
worry about it at all.

Thanks, though.
Well, if you haven't actually tried listening to the focus, how have you
tried to update on focus change?
 
J

Jason Cavett

Well, if you haven't actually tried listening to the focus, how have you
tried to update on focus change?

As I was typing out what I have tried so far, I think I may have come
up with a solution. Problem is, it would require the use of a
singleton which would couple the code more but, it's all GUI code so
it's not a huge deal.

Either way, before I move ahead, I just wanted to see if there is some
sort of "global watch" system in Swing to monitor event across the
entire Swing system (such as focus changes, etc). If not, I'll figure
out another way. I just wanted to ask first.
 
L

Larry Barowski

Jason Cavett said:
Is there a way to track component focus across an entire GUI? What I
am trying to do is keep toolbars updated (by updating their
corresponding actions) depending on what component is currently in
focus.

You can use Toolkit.addAWTEventListener with a
FOCUS_EVENT_MASK.
 
J

Jason Cavett

You can use Toolkit.addAWTEventListener with a
FOCUS_EVENT_MASK.

Awesome...that worked (pretty well, I might add).

After doing a little research though, Sun seems to suggest that this
can cause speed issues within the GUI. Is this true? Have you ever
noticed a problem as a result (since, essentially, you're capturing
every event that happens in the system).

Thanks again.
 
L

Larry Barowski

Jason Cavett said:
Awesome...that worked (pretty well, I might add).

After doing a little research though, Sun seems to suggest that this
can cause speed issues within the GUI. Is this true? Have you ever
noticed a problem as a result (since, essentially, you're capturing
every event that happens in the system).

With all the time consuming things that go on in a gui, this should
be a tiny contribution. It is used in jGRASP to implement
focus-follows-mouse behavior within a JDesktopPane. The mask
is for focus, mouse, and mouse motion events. When ffm is
turned off, the listener is removed. Any difference in speed for
the ffm on and off states is undetectably small.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top