Swing - how to catch all events

V

VD

Programming in java for a while now, but I still have this silly
problem that I don't know if the experts has a simple answer.

I have a Swing app. Yes, simple stuff eh. Next, user logins to use
the app. If they don't do anything (mouse move, key press) for a
while, then I log out. The think is that detecting a mouse event, I
have to register with each of the tabpane of the app. I don't like
that. Also, I have to register with each components within the panel.
The same for keyboard. For keyboard, it seems I can register event
for just any component (with appropriate modifer to get the input map
and action map). However, I still have to register all keys which are
alot. I want the ability to catch the event from top down. Anyevent
would goes through my filters first. Would this be possible? How do
I solve this simple and common problem? Thank you very much in
advance.
 
R

Robert Olofsson

: Programming in java for a while now, but I still have this silly
: problem that I don't know if the experts has a simple answer.

: while, then I log out. The think is that detecting a mouse event, I
: have to register with each of the tabpane of the app. I don't like
: that. Also, I have to register with each components within the panel.
: The same for keyboard. For keyboard, it seems I can register event
: ....

You probably want to look at this:
http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html#glasspane

/robo
 
A

Adam

I have a Swing app. Yes, simple stuff eh. Next, user logins to use
the app. If they don't do anything (mouse move, key press) for a
while, then I log out. The think is that detecting a mouse event, I
have to register with each of the tabpane of the app. I don't like
that. Also, I have to register with each components within the panel.
The same for keyboard. For keyboard, it seems I can register event
for just any component (with appropriate modifer to get the input map
and action map). However, I still have to register all keys which are
alot. I want the ability to catch the event from top down. Anyevent
would goes through my filters first. Would this be possible? How do
I solve this simple and common problem? Thank you very much in
advance.

About the keyboard you might want to look at
KeyEventPostProcessor
added to KeyboardFocusManager

Adam
 
V

VD

Thank you all for helping me out. I haven't tried your solution yet,
I'll check them out though. Now, I got the solution that currently
works. I am not sure if it's a recommended way of doing things or
not, but very nice and easy to do. First, get a toolkit:

Toolkit toolkit = mycomponent.getToolkit();
toolkit.addAWTEventListener()... or something like this.

//void addAWTEventListener(AWTEventListener listener, long eventMask)

it takes 2 argument, the first one is the listener, the 2nd is the
long modifier which could be:

long mymodifier = AWTEvent.KEY_EVENT_MASK | MOUSE_EVENT_MASK |
MOUSE_MOTION_EVENT_MASK;

That would do it for me. This problem is so common that I think
almost any Swing GUI program will soon or later encounter it.
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top