Can One Clip to a Box while Drawing on a <JPanel>?

K

kvnsmnsn

Is there some way to draw on a <JPanel> or write a <String> to it in
such a way that only the portion of what I'm drawing or writing that
takes place inside a box gets shown? I'd like to have three windows
show up in my <JPanel>, and I'd like to draw things to them, but it's
possible that the things I'm drawing to them might extend beyond one
such window's boundaries and I don't want that to happen. For ex-
ample, if I'm drawing "the sky is blue" to one such window and the
lower part of that string would end up outside the window's bounda-
ries, then I only want the top part of each character to be drawn.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
D

Daniel Pitts

Is there some way to draw on a <JPanel> or write a <String> to it in
such a way that only the portion of what I'm drawing or writing that
takes place inside a box gets shown? I'd like to have three windows
show up in my <JPanel>, and I'd like to draw things to them, but it's
possible that the things I'm drawing to them might extend beyond one
such window's boundaries and I don't want that to happen. For ex-
ample, if I'm drawing "the sky is blue" to one such window and the
lower part of that string would end up outside the window's bounda-
ries, then I only want the top part of each character to be drawn.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_


There are two ways to do this, but the best way would be to have each
of your "boxes" be individual components, such as JComponent.

Alternatively, you can use Graphics.setClip(), but its definitely
better to go the JComponent approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,786
Messages
2,569,625
Members
45,320
Latest member
icelord

Latest Threads

Top