// get the resize ratio
double resize = (iconSize - 9)
/ (bounds.getWidth() > bounds.getHeight() ? bounds
.getWidth() : bounds.getHeight()) ;
// resize graphics
shape.transform(AffineTransform.getTranslateInstance(
-shape.getBounds().getCenterX(),
-shape.getBounds().getCenterY()));
shape.transform(AffineTransform.getScaleInstance(resize, resize));
// now move it to centre of the icon