tags:

views:

122

answers:

1

When drawing various things using a Graphics2D object and BasicStroke at 1.0f, I can't seem to get the g2d object to honor my RenderingHints settings. Specifically the *KEY_ANTIALIASING* set to *VALUE_ANTIALIAS_ON*.

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;

    g2d.setStroke(new BasicStroke(1.0f));
    g2d.setRenderingHint(
     RenderingHints.KEY_ANTIALIASING,
     RenderingHints.VALUE_ANTIALIAS_ON
    );

    // draw stuff...
}

Are there other keys I should be using? Am I not applying the keys in the appropriate place? Using it the way described above results in normal, pixelated shapes being drawn.

+1  A: 

If you are stroking (as it looks like you are from your snippet), you might want to also try:

g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
jedierikb
When I try and use the stroke control key, I still get no effect. It is still pixelated (no anti-aliasing). Any other suggestions?
spligak
In a JPanel with g2d.drawOval( 10, 10, 300, 300 ); w/o your hints looks bad. W/ your hints, looks good. What type of object are you drawing into? What are you drawing?
jedierikb
I'm drawing directly into a JFrame, would that have a significant impact on this? It seems Graphics2D should be the same anywhere you attempt to use it. Is it limited when used in this particular context?
spligak
Just grasping at straws here, thought maybe you were painting into something funky (an SVG or PDF context). I tried extending a JFrame using your overridden paint method to g2d.drawOval( 10, 10, 300, 300 ); and it looks smooth. Sorry! If I think of something, I'll post.
jedierikb