• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The KeyboardFocusManager getFocusOwner() method will return the component that currently has focus.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can start by reading the API for the class mentioned.
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay Thanks for this information

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

Thanks
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you very much for your help

yea it's working now,

Thanks
 
Farhad Rahmati
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!