Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Anti-aliased rounded JDialog

843807Mar 12 2010 — edited Jun 14 2010
{noformat}Hi,{noformat}
I'm trying to create a rounded JDialog, with anti-aliasing applied to the edges. To set the window shape, I use the following code:
RoundRectangle2D.Double roundRect = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 15, 15);
AWTUtilities.setWindowShape(this, roundRect);
This will round the edges of my JDialog, but no anti-aliasing is applied. To enable anti-aliasing for this dialog, I've created this paint method:
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
RenderingHints rh = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHints(rh);
RoundRectangle2D.Double roundRect = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), 15, 15);
AWTUtilities.setWindowShape(this, roundRect);
super.paint(g2);

RoundRectangle2D.Double roundRect2 = new RoundRectangle2D.Double(1, 1, getWidth() - 3, getHeight() - 3, 15, 15);
g2.draw(roundRect);
}
roundRect2 is anti-aliased, but the roundRect isn't. Any ideas please on what I'm doing wrong, or how I can achieve the desired effect?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2010
Added on Mar 12 2010
4 comments
1,151 views