Fill an oval with a gradient [message #226323] |
Thu, 09 November 2006 11:59 |
Andreas Walter Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Hi everybody,
I'm trying to fill an oval with a gradient, but the Graphics class
only allows to fill a rectangle with a gradient. The (not very
efficient) solution I implemented so far is filling a rectangle with
the gradient (with fillRectangle(Rectangle r)), then painting all points
within that rectangle that are not contained in the oval with the
background color to 'delete' the gradient points outside the oval, and
finally draw the oval around the 'rest' of the gradient. The Graphics
class offers a method setClip(Path) which seems to offer the needed
functionality, but I haven't figured out so far how I could use it,
especially since the Path object has to be constructed with a Device
object, and I dont't know how to get that, because I don't know how to
access the Display from my figure class. Any help would be appreciated.
Thanks in advance,
Andreas
|
|
|
Re: Fill an oval with a gradient [message #239624 is a reply to message #226323] |
Tue, 06 November 2007 08:39 |
Eclipse User |
|
|
|
Originally posted by: trommas.yahoo.com
Did you find a better solution for this?
I would love to see any code example that fills a gradient on something
else than a rectangle :)
Best Regards,
Tomas Zijdemans
Andreas Walter wrote:
> Hi everybody,
>
> I'm trying to fill an oval with a gradient, but the Graphics class
> only allows to fill a rectangle with a gradient. The (not very
> efficient) solution I implemented so far is filling a rectangle with
> the gradient (with fillRectangle(Rectangle r)), then painting all points
> within that rectangle that are not contained in the oval with the
> background color to 'delete' the gradient points outside the oval, and
> finally draw the oval around the 'rest' of the gradient. The Graphics
> class offers a method setClip(Path) which seems to offer the needed
> functionality, but I haven't figured out so far how I could use it,
> especially since the Path object has to be constructed with a Device
> object, and I dont't know how to get that, because I don't know how to
> access the Display from my figure class. Any help would be appreciated.
>
> Thanks in advance,
> Andreas
|
|
|
Re: Fill an oval with a gradient [message #239695 is a reply to message #239624] |
Thu, 08 November 2007 21:07 |
Rene Dekker Messages: 9 Registered: July 2009 |
Junior Member |
|
|
Not sure why you have a problem with this. Here is a snippet of code that
works for me:
@Override
public void paintClientArea( Graphics graphics )
{
graphics.pushState();
Color lightBlue = new Color( null, 245, 245, 255 );
Rectangle rect = new Rectangle( bounds );
rect.height = 30;
graphics.setBackgroundPattern( new Pattern( null, rect.x, rect.y,
rect.x, rect.y + rect.height, lightBlue,
ColorConstants.darkBlue ) );
graphics.fillOval( rect );
graphics.popState();
}
Tomas Zijdemans wrote:
> Did you find a better solution for this?
> I would love to see any code example that fills a gradient on something
> else than a rectangle :)
> Best Regards,
> Tomas Zijdemans
> Andreas Walter wrote:
>> Hi everybody,
>>
>> I'm trying to fill an oval with a gradient, but the Graphics class
>> only allows to fill a rectangle with a gradient. The (not very
>> efficient) solution I implemented so far is filling a rectangle with
>> the gradient (with fillRectangle(Rectangle r)), then painting all points
>> within that rectangle that are not contained in the oval with the
>> background color to 'delete' the gradient points outside the oval, and
>> finally draw the oval around the 'rest' of the gradient. The Graphics
>> class offers a method setClip(Path) which seems to offer the needed
>> functionality, but I haven't figured out so far how I could use it,
>> especially since the Path object has to be constructed with a Device
>> object, and I dont't know how to get that, because I don't know how to
>> access the Display from my figure class. Any help would be appreciated.
>>
>> Thanks in advance,
>> Andreas
|
|
|
Powered by
FUDForum. Page generated in 0.01711 seconds