Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2006

Tip: Looking for answers? Try searching our database.

fillArc() and drawArc() seem not to match bounds

Thread view: 
Monique Y. Mudama - 25 Apr 2006 18:05 GMT
Below is a full, short code example.  I purposely used angles of 90 and
180, which seemed like the simplest case.

There seems to be a one pixel discrepancy between the fill and the
drawn line that extends roughly through the lower right quadrant.

Image of the problem: http://www.bounceswoosh.org/misc/pie.png

Is there something I should be doing differently in order to get the
line to exactly match the edge of the fill?

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class SimpleArcTest extends JPanel
{
   protected int angles[] = {90, 90, 180};
   protected Color colors[] = {Color.BLUE, Color.MAGENTA, Color.DARK_GRAY};
   
   public static void main(String[] args)
   {
       JFrame frame = new JFrame();
       JPanel panel = new SimpleArcTest();
       panel.setBackground(Color.WHITE);
       
       panel.setPreferredSize(new Dimension(400,400));
       
       frame.getContentPane().add(panel);
       
       frame.pack();
       frame.setVisible(true);
   }
   
   protected void paintComponent(Graphics g)
   {
       super.paintComponent(g);
       
       int startAngle = 0;
       
       for (int i = 0; i < angles.length; i++)
       {
           g.setColor(colors[i]);
           g.fillArc(getX(), getY(), getWidth(), getHeight(),
                   startAngle, angles[i]);
           
           g.setColor(Color.BLACK);
           g.drawArc(getX(), getY(), getWidth(), getHeight(),
                   startAngle, angles[i]);
           
           startAngle += angles[i];
       }
   }
}

Signature

monique

Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html

Monique Y. Mudama - 25 Apr 2006 19:27 GMT
> Below is a full, short code example.  I purposely used angles of 90
> and 180, which seemed like the simplest case.
[quoted text clipped - 6 lines]
> Is there something I should be doing differently in order to get the
> line to exactly match the edge of the fill?

It looks like most bug reports for the fillArc() and drawArc() methods
of Graphics have been closed, saying to use Arc2D instead.

Arc2D seems not to have these issues, so I guess that's my route.

Signature

monique

Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.