public static void fillPaintedShape(Graphics2D graphics,Shape shape,Paint paint,Rectangle2D paintBounds){
  if (shape == null) {
    return;
  }
  if (paintBounds == null) {
    paintBounds=shape.getBounds2D();
  }
  AffineTransform txOrig=graphics.getTransform();
  graphics.translate(paintBounds.getX(),paintBounds.getY());
  graphics.scale(paintBounds.getWidth(),paintBounds.getHeight());
  Paint paintOld=null;
  if (paint != null) {
    paintOld=graphics.getPaint();
    graphics.setPaint(paint);
  }
  AffineTransform tx=AffineTransform.getScaleInstance(1.0 / paintBounds.getWidth(),1.0 / paintBounds.getHeight());
  tx.translate(-paintBounds.getX(),-paintBounds.getY());
  graphics.fill(tx.createTransformedShape(shape));
  if (paintOld != null) {
    graphics.setPaint(paintOld);
  }
  graphics.setTransform(txOrig);
}

public static void fillPaintedShape ( Graphics2D graphics , Shape shape , Paint paint , Rectangle2D paintBounds ) { if ( shape == null ) { return ; } if ( paintBounds == null ) { paintBounds = shape . getBounds2D ( ) ; } AffineTransform txOrig = graphics . getTransform ( ) ; graphics . translate ( paintBounds . getX ( ) , paintBounds . getY ( ) ) ; graphics . scale ( paintBounds . getWidth ( ) , paintBounds . getHeight ( ) ) ; Paint paintOld = null ; if ( paint != null ) { paintOld = graphics . getPaint ( ) ; graphics . setPaint ( paint ) ; } AffineTransform tx = AffineTransform . getScaleInstance ( 1.0 / paintBounds . getWidth ( ) , 1.0 / paintBounds . getHeight ( ) ) ; tx . translate ( - paintBounds . getX ( ) , - paintBounds . getY ( ) ) ; graphics . fill ( tx . createTransformedShape ( shape ) ) ; if ( paintOld != null ) { graphics . setPaint ( paintOld ) ; } graphics . setTransform ( txOrig ) ; }
fills a shape with the specified paint object .
