fillArc() and drawArc() seem not to match bounds
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];
}
}
}
--
monique
Help us help you:
http://www.catb.org/~esr/faqs/smart-questions.html