You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Guanming Wu <gw...@physiome.com> on 2002/10/07 21:54:02 UTC

Change fill color in a GraphicsNode

Hi,

 

I am new to batik-1.1.1. In one of my applications, I want to paint a
GraphicsNode with different colors at different places in a JPanel. In my
application, I cannot directly use JSVGComponent or JSVGCanvas, so I embed a
SVG in my graphics context by painting a GraphicsNode directly on Graphics2D
(Method: Graphics2D.paint(Graphics2D)).

 

I just want if there is a way to set fill color after GraphicsNode is built
from SVG document.

 

Thanks,

 

Guanming


Re: Change fill color in a GraphicsNode

Posted by Philippe Converset <pc...@Qarbon.com>.
Hi,

If your GraphicsNode is a ShapeNode, then you can use the 
setShapePainter() method.

Here is an example:

      FillShapePainter painter;

      painter = new FillShapePainter(shapeNode.getShape());
      painter.setPaint(Color.RED);
      shapeNode.setShapePainter(painter);
      shapeNode.paint(g2d);

If you want to specify the stroke paint, then you can use 
StrokeShapePainter and if you want to specify the stroke and the fill 
paint at the same time, then you must use a CompositeShapePainter on 
which you add the two previous painters through the addShapePainter() 
method.

Hope this helps.

Philippe

Guanming Wu a écrit:

> Hi,
>
>  
>
> I am new to batik-1.1.1. In one of my applications, I want to paint a 
> GraphicsNode with different colors at different places in a JPanel. In 
> my application, I cannot directly use JSVGComponent or JSVGCanvas, so 
> I embed a SVG in my graphics context by painting a GraphicsNode 
> directly on Graphics2D (Method: Graphics2D.paint(Graphics2D)).
>
>  
>
> I just want if there is a way to set fill color after GraphicsNode is 
> built from SVG document.
>
>  
>
> Thanks,
>
>  
>
> Guanming
>