?
Solved

Anti-aliasing with awt.Graphics2D

Posted on 2005-03-14
8
Medium Priority
?
543 Views
Last Modified: 2008-01-09
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
Comment
Question by:eeBlueShadow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13540461
your only antialiasing the text
0
 
LVL 92

Expert Comment

by:objects
ID: 13540465
use KEY_ANTIALIASING
0
 
LVL 92

Accepted Solution

by:
objects earned 1600 total points
ID: 13540469
and VALUE_ANTIALIAS_ON

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 10

Author Comment

by:eeBlueShadow
ID: 13540479
Hmm, thought it would be that simple. The line

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

gives the same results
0
 
LVL 92

Expert Comment

by:objects
ID: 13540485
what platform (it is only a hint)
0
 
LVL 10

Author Comment

by:eeBlueShadow
ID: 13540492
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
 
LVL 10

Author Comment

by:eeBlueShadow
ID: 13540502
http://blueshadow.no-ip.com/ee/noalias2.jpg shows the actual size and 400% zoom of the component
0
 
LVL 10

Author Comment

by:eeBlueShadow
ID: 13540530
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question