Thanks Jim.  I don't know how I missed that in the Shape JavaDoc, must
have glazed over it thinking it was just another Rectangle2D.  I've
tried setting the clip in the component using RoundRectangle2D.Double
and it seems to work with all the implementations I've checked.  I'm
wondering though, is this an appropriate technique or am I destined for
a world of hurt doing that? ex:

protected void paintComponent(final Graphics g) {
  if (strategy != null) {
      final Graphics2D scratchGraphics = (Graphics2D) g.create();
      final Insets insets = getInsets();
      scratchGraphics.translate(insets.left, insets.top);
      if (roundedCorners) {
          // Returns the round rectangle based on the x, y, width, height
          final Shape clip = calculateClip(0, 0, getWidth() -
insets.left - insets.right,
                                                          getHeight() -
insets.top - insets.bottom);
          scratchGraphics.setClip(clip);
      }
      // Delegates to the strategy passing the width and height to be
filled
      strategy.paint(this, scratchGraphics, getWidth() - insets.left -
insets.right,
                           getHeight() - insets.top - insets.bottom);
      scratchGraphics.dispose();
  } else {
      super.paintComponent(g);
  }
}

P.S. Sorry Jim for the duplicate, I didn't notice that the reply-to on
the list wasn't back to the list.

Jim wrote:
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/geom/RoundRectangle2D.html


RoundRectangle2D rect = ...
Graphics2D g2d = ...
g2d.draw(rect);


Ken Blair wrote:

   I apologize if this is an overly asked question but I'm having
little luck finding an answer.  What is a fast technique for painting a
square image and rounding the corners?  I have a number of custom
components that delegate painting their backgrounds using Strategy and a
number of the implementations paint images.  The implementations might
scale the image, tile it, paint it in a certain location on a matte,
etc. and I'd like to be able to support rounded corners.  Any help is
appreciated.

Regards,
Ken Blair

===========================================================================


To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================

To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".



===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to