简体   繁体   English

drawOval的异常行为

[英]Unexpected behavior for drawOval

I'm facing problem with drawOval function. 我面临着drawOval函数的问题。 I use it to draw circle but the result doesn't look like a circle. 我用它来画圆,但是结果看起来并不像一个圆。 I think this behavior happened after certain height for Jpanel. 我认为这种行为在Jpanel达到一定高度后发生。 Scroll down till the end and you can get the result as shown in the attached image below. 向下滚动到最后,您可以得到如下图所示的结果。 Could anyone offer an explanation for this? 有人可以为此提供解释吗?

Result after Execute the sample program 执行示例程序后的结果

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class TestMain
{
    public static void main(String[] args)
    {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JScrollPane jsp = new JScrollPane();
        jsp.setViewportView(new TestPanel());
        f.getContentPane().add(jsp);
        f.setSize(500,400);
        f.setLocation(200,200);
        f.setVisible(true);
    }
}

class TestPanel extends JPanel
{
    public TestPanel()
    {
        setPreferredSize(new Dimension(1960 , 77660240));
        setBackground(Color.white);
    }

    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawRect(30, 77660141, 100, 20);
        g2.drawOval(15, 77660141, 10, 10);
        g2.draw(new Ellipse2D.Double(140, 77660141,
                             10,
                             10));
        g2.draw(new Ellipse2D.Double(160, 77660141,
                             10,
                             10));
        g2.draw(new Ellipse2D.Double(180, 77660141,
                             10,
                             10));
        g2.draw(new Ellipse2D.Double(200, 77660141,
                             30,
                             30));
    }
}

将面板的尺寸更改为更合理的尺寸,例如:1000,它将可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM