• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

repainting in shapes other than square

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I want to do is to repaint a square component but only a portion of it say in a circular shape. Something like.... repaint(10,10,new Circle()) ... I think that gets the point across. I do not want to repaint the entire component just some portion of it in a shape other than repaint(0,0,getWidth(),getHeight()) type of deal.

Thanks in advance,
Christopher Dancy
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The repaint area must be a Rectangle.

Why does this cause a problem? If we know the problem maybe we can provide a solution.

The Graphics2D class support a draw(Shape) and fill(Shape) methods which may help.
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Dancy wrote:What I want to do is to repaint a square component but only a portion of it say in a circular shape. Something like.... repaint(10,10,new Circle()) ... I think that gets the point across. I do not want to repaint the entire component just some portion of it in a shape other than repaint(0,0,getWidth(),getHeight()) type of deal.

Thanks in advance,
Christopher Dancy



I'm not sure this is the answer you are looking for, but think about the definition of drawOval and fillOval, and I think you will see that if you replace fillRect by fillOval, and leave the parameters the same then you will get exactly the result you are looking for. Because drawOval and FillOval are expressed relative to the rectangular shape they occupy.

The drawArc and fillArc methods are also relative to the rectangle it would occupy if the arc was drawn a full 360 degrees

maybe this document will help you

http://richardbowles.tripod.com/java/guide/graphics.htm

Does this help?
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The component is rectangular shaped. What we are playing around with is different effects to transition to the next stage/component within that same area. So my brilliant idea was to, from the center of the component repaint outwardly, with ever increasing in size circles, until the new component is made visible, if that makes sense. As I'm writing this now I'm thinking that maybe by setting a composite of some sort I can get the desired effect.
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chris Dancy wrote:The component is rectangular shaped. What we are playing around with is different effects to transition to the next stage/component within that same area. So my brilliant idea was to, from the center of the component repaint outwardly, with ever increasing in size circles, until the new component is made visible, if that makes sense. As I'm writing this now I'm thinking that maybe by setting a composite of some sort I can get the desired effect.



OK, well if you are just using draw and fill commands to display the transition to the next component, then I'd say you can do what you describe by expressing the parameters of the drawOval command as functions of the co-rdinates of the first rectangular component, and incrementing the draw parameters in a for loop, until you reach the co-ordinates of the rectangle.

But anyways, that's just one way to look at it, I'm sure there are others.
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So my brilliant idea was to, from the center of the component repaint outwardly, with ever increasing in size circles,



Well, its still not a problem using a Rectangle.

There are many different ways to solve the problem. Presumably you have a Timer to schedule the transition. So every time the paintComponent() method is invoked you simply draw a different sized oval. So you would need to keep track of the size of the oval. This could be done by keep a class variable for the current size. Or you could get the size of the Rectangle to be repainted from the Graphics clip bounds.
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob: That's what my initial idea was, however I was not sure if I simply was not aware of some way to hack repaint, maybe a custom paint manager, to get it to repaint in different shapes other than rectangles...like repaint(x,y,width,height) but do something like repaint(0,0,Circle). I know there is no documented way of doing this, I just thought maybe some of you guys might have done this kind of effect before and know an easy way to accomplish it, not that the way Rob has put is hard by any measure. So I'll go with that than. Thanks
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the center of the component repaint outwardly, with ever increasing in size circles, until the new component is made visible
If you want all circles/ovals with a common center you could start from the outside with fillOval and move toward the center with different colors and decreasing radius or width/height values.
Other shapes, eg, polygons could be handled the same way.

no documented way of doing this
We do have the Area class that allows complex geometry primitives to be created.
See Constructing Complex Shapes from Geometry Primitives.

Another possibility is to set a clipping shape for filling. The Graphics setClip method takes a Shape argument, eg, Ellipse2D, Path2D, Polygon. You can do this at any location. Make sure you restore the clip to its original value before leaving the painting method.
See Clipping the Drawing Region.

Edit: fix url.
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep I'd say there's a good half dozen ways to get this job done.
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By no documented way I meant no way to say repaint( new Triangle()) or something to that effect. I did in fact set the clip as a Circle and simply drew bigger circles until the component was completely redrawn. Thanks for the tips however.
 
reply
    Bookmark Topic Watch Topic
  • New Topic