Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing the Mouse to stay inside a Window/Frame/Dialog

Status
Not open for further replies.

Watts

Programmer
Jan 18, 2001
80
US
Is there any way to do this? I want to open a Dialog and force the mouse to stay inside the dialog until the Dialog is dealt with (closed).
 
with a dialog, normally focus will remain on it until it is dealt with anyway. Not sure you can force the mouse to stay within an existing dialog frame such as a JOptionPane etc.
Sorry, I don't have any code but a general principle may be as follows:
What you may have to do is create you own dialog, get its exact size (height and width), and use this data to calculate where it is when in position on screen (e.g. by getting X and Y and then doing the calculations. Then have a mouse listener attached to the dialog that checks the pointer X and Y every time it moves, if it moves out of your predetermined boundaries then just redraw the pointer at the edge of the box.

I have done this with an icon within a JFrame but never with a mouse pointer, so not sure it can be done (but I expect it can).

Sorry can't be more help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top