Search code examples
javaswingparametersgraphics2d

Height parameter in Graphics2D.drawArc


I'm trying to create an arc, but when I use the same width and height parameters, the arc is almost flat, shouldn't it be higher? I would have expected that the height would appear to be the same length as the width on the screen.

public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.drawArc(0, 0, 100, 100, 45, 90);
}

Solution

  • g2d.drawArc(0, 0, 100, 100, 45, 90, Arc2D.CHORD);
    

    I would have expected that the height would appear to be the same length as the width on the screen.

    It is because you only draw an arc of 90 degrees. Change the value to 180 and the width/height will be different. Even if you draw 180 the width/height won't be the same. The width/height will only be the same for a 360 degree arc.

    Also, what API are you using? Graphics.drawArc(...) only supports 6 parameters, not 7.

    Post a proper SSCCE when you ask a question so we can see the behaviour.