aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to send a mouse event to a component where cursor is? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to send a mouse event to a component where cursor is?" Watch "How to send a mouse event to a component where cursor is?" New topic
Author

How to send a mouse event to a component where cursor is?

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi Friends

I am working on a touch screen project. I need to develop a touch screen keyboard for this application

I know how to send the mouse event to a specific component like JTextField

but I don't know, how to send a mouse event to a component where the cursor is.

Can you help me please, I really don't have any idea about.

Thanks

Farhad
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
The KeyboardFocusManager getFocusOwner() method will return the component that currently has focus.
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
hi Rob

Can you please please, provide more detail about it,

I mean about KeyboardFocus manager and it's method.

and how to implement it.

Thanks for your reply, I appriciate it.

Farhad
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
You can start by reading the API for the class mentioned.
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Okay Thanks for this information

all I need, is a start point and I could find it.

Thanks
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
HI Rob,

Thanks for your information after reading and some search finally I manage to do it, but still a tiny problem. I hope you can help me solve it

first Let me tell you what I did.

first thing, I made a method called whoWasFocused() here is the code


then I called this method when each textBox is gainedFocused.
so finally when you click the buttons, it adds its text in to the a variable.


it works fine, but I am not sure if it is the way to do it. when you click the buttons, the cursor is not in the text field, because the button is focused
I want the cursor to be in the text field while you are pressing the buttons.

Thanks
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2182
    
    7
I want the cursor to be in the text field while you are pressing the buttons.


When you create the button you need to use:

Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96

Thank you very much for your help

yea it's working now,

Thanks
Farhad Rahmati
Ranch Hand

Joined: Dec 16, 2010
Posts: 96
Hi Rob

what do you think, if I put the buttons in a separt window not focusable and cursor shoud be on the focused text box where the user wants.

something like Screen Key board in windows.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send a mouse event to a component where cursor is?