Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Clipping question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Clipping question" Watch "Clipping question" New topic

Clipping question

J Wallace

Joined: Jan 30, 2008
Posts: 5
I'm having a problem with clipping bounds not being what I expect them to be. I must not fully understand what's going on. Here is a simple example to illustrate the problem:

In the code above, java.awt.Rectangle[x=0,y=0,width=98,height=144] is initially printed. This seems like a reasonable clip. However, when I scroll down one unit, I get java.awt.Rectangle[x=0,y=144,width=98,height=1]. What is happening here? I was expecting to see something like java.awt.Rectangle[x=0,y=1,width=98,height=144]. Also, if I then scroll back up one unit, I get java.awt.Rectangle[x=0,y=0,width=98,height=1]. Why is it not back to the original clip?

Can someone please explain what's going on? Thank you.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2451
When scrolling in a viewport you don't need to repaint the entire component, only the part that wasn't visible in the viewport before.

So the first time you need to paint everything.

When you scroll down 1 pixel you only need to paint the 1 pixel line at the bottom of the viewport.

When you scroll up 1 pixel you only need to repaint the 1 piexl line at the top of the viewport.
J Wallace

Joined: Jan 30, 2008
Posts: 5
Thank you. This makes perfect sense now.
I agree. Here's the link:
subject: Clipping question
It's not a secret anymore!