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).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.