Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Anti-aliasing with awt.Graphics2D

Hi guys, I'm having problems anti-aliasing things.

I have the following paint() method:

public void paint(Graphics g) {

      Graphics2D g2 = (Graphics2D)g;

      Stroke oldStroke = g2.getStroke();
      g2.setStroke(new BasicStroke(3));
      g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                  
      if(selected) {
            g2.setPaint(TVBank.BUTTON_BGROUND_HILITE);
            g2.fillRoundRect(0, 0, getWidth(), getHeight(),cornerRadius,cornerRadius);
            g2.setPaint(TVBank.BUTTON_BORDER_HILITE);
            g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1,cornerRadius,cornerRadius);
      } else {
            g2.setPaint(TVBank.BUTTON_BGROUND_COLOUR);
            g2.fillRoundRect(0, 0, getWidth(), getHeight(),cornerRadius,cornerRadius);
            g2.setPaint(TVBank.BUTTON_BORDER_COLOUR);
            g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1,cornerRadius,cornerRadius);
      }
      g2.setStroke(oldStroke);
}

but this gives the following: http://blueshadow.no-ip.com/ee/noalias.jpg

What am I doing wrong?
0
eeBlueShadow
Asked:
eeBlueShadow
  • 4
  • 4
1 Solution
 
objectsCommented:
your only antialiasing the text
0
 
objectsCommented:
use KEY_ANTIALIASING
0
 
objectsCommented:
and VALUE_ANTIALIAS_ON

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
eeBlueShadowAuthor Commented:
Hmm, thought it would be that simple. The line

      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

gives the same results
0
 
objectsCommented:
what platform (it is only a hint)
0
 
eeBlueShadowAuthor Commented:
Cancel that, it doesn't gove the same results, but the corners still look thicker than they should do. Still, my bad for copy/pasting from the wrong bit of the tutorial
0
 
eeBlueShadowAuthor Commented:
http://blueshadow.no-ip.com/ee/noalias2.jpg shows the actual size and 400% zoom of the component
0
 
eeBlueShadowAuthor Commented:
OK, I've found that adding another RenderingHint works:

g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

But thanks for the help in the anti-aliasing :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now