wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Keeping the Mouse inside a JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Keeping the Mouse inside a JPanel" Watch "Keeping the Mouse inside a JPanel" New topic
Author

Keeping the Mouse inside a JPanel

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

My 3 year old son loves to use Paint Shop Pro. But he hasn't quite got the concept of the relationship between the mouse and the pointer on screen. So he spends half his time moving the mouse around outside of the painting area.

Anyway, I thought I could construct a very simple basic paint program if I could figure out someway to keep the mouse cursor inside a specified JPanel area. That way, he could move the mouse around as much as he wants and always be on the paintable canvas.

If anyone has any insight into this, please let me know.

Thanks.


GenRocket - Experts at Building Test Data
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Why not just maximize the window in Paint Shop Pro? Or use some other drawing program that can make the drawing canvas full-screen? (The Gimp?)

brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
Hey I've got a similiar issue with my 3 year old daughter! I wanted to let her 'use' the computer like daddy, but she has a hard time clicking 'where she should'.

I've almost finished a program you might like. It opens a jframe that is maximized. The screen has 4 image areas, which have a randomly colored ellipse drawn. At the bottom is a rainbow colored next button.

As my daughter clicks the ellipse buttons, they switch to a picture. If she clicks them again, they switch back to a new colored ellipse. When the next button is clicked, the buttons all swap to new colored ellipses, with new pictures under them.

To add pictures, you simply drop whatever JPG/PNG/GIF you want into a picture directory and run the app. I've got pictures of her relatives and friends in the pics dir. I'm collecting pictures of her favorite child characters such as Dora, the Wiggles, Blue, etc, so she can uncover them as she's clicking around!

Everything is jumbo sized for her, so she can easily click and make things happen. I've just added sound to, so that a random sound is heard each time she clicks a button. Its not quite working right between 1.4.2 and 1.5.0beta.

I'd be happy to send it to you.

Regards,
Aaron R>
[ May 18, 2004: Message edited by: Aaron Roberts ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Aaron Roberts:
Hey I've got a similiar issue with my 3 year old daughter! I wanted to let her 'use' the computer like daddy, but she has a hard time clicking 'where she should'.

I've almost finished a program you might like. It opens a jframe that is maximized. The screen has 4 image areas, which have a randomly colored ellipse drawn. At the bottom is a rainbow colored next button.

As my daughter clicks the ellipse buttons, they switch to a picture. If she clicks them again, they switch back to a new colored ellipse. When the next button is clicked, the buttons all swap to new colored ellipses, with new pictures under them.

To add pictures, you simply drop whatever JPG/PNG/GIF you want into a picture directory and run the app. I've got pictures of her relatives and friends in the pics dir. I'm collecting pictures of her favorite child characters such as Dora, the Wiggles, Blue, etc, so she can uncover them as she's clicking around!

Everything is jumbo sized for her, so she can easily click and make things happen. I've just added sound to, so that a random sound is heard each time she clicks a button. Its not quite working right between 1.4.2 and 1.5.0beta.

I'd be happy to send it to you.

Regards,
Aaron R>

[ May 18, 2004: Message edited by: Aaron Roberts ]


Aaron, that would be great if you could send that to me.

I'd also like to figure out if what I want to do with the mouse and the canvas is possible. Thanks.
Aaron Roberts
Ranch Hand

Joined: Sep 10, 2002
Posts: 174
You could probably make a mouselistener that listened for exit events (when the mouse have left the component). Once this happens, you could use java.awt.Robot to reposition the mouse backinside the bounds of the drawing area.

Go to -

Game Source Code

and get the source code for ch3. Use ant to compile it. If you run the MouseTest or MouselookTest examples, you should get a good idea of how things could work. The examples are done in full screen mode, but they still apply.

I'll email you the code after I get home tonight.

Regards,
Aaron R>
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Aaron Roberts:
You could probably make a mouselistener that listened for exit events (when the mouse have left the component). Once this happens, you could use java.awt.Robot to reposition the mouse backinside the bounds of the drawing area.

Go to -

Game Source Code

and get the source code for ch3. Use ant to compile it. If you run the MouseTest or MouselookTest examples, you should get a good idea of how things could work. The examples are done in full screen mode, but they still apply.

I'll email you the code after I get home tonight.

Regards,
Aaron R>


Thanks Aaron!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Keeping the Mouse inside a JPanel