Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setClip() not working  RSS feed

 
Eureka Jana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a paint method for a component in Swing.
I want to make the clip region in the Graphics object of the paint method to be some what larger than the original clipping region. I am using the following lines of code.
Rectangle old = g.getClip();
Rectangle clip = g.getClipBounds();
g.setClip(clip.x, clip.y, clip.width + 20, clip.height + 20);
clip = g.getClipBounds();
g.drawLine(clip.x, clip.y, clip.width, clip.height);
g.setClip(old);
But it seems that it is not working. I am not able to see the line in the new clipping region. The line appears in the old clipping region. What may be the reason.
Thanks,
Jana
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you repaint?
Also if no clip has previously been set then getClip() and getClipBounds() returns null.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!