Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:11:43+00:00 2026-06-16T07:11:43+00:00

The code below draws rectangle and 2 ellipses. While should draw 3 ellipses. My

  • 0

The code below draws rectangle and 2 ellipses.

enter image description here

While should draw 3 ellipses.

My OS is Windows 7 prof 64 bit

My Java is 1.6 x86 also 1.7 x64 tested.

Why?

package tests;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;

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

import net.miginfocom.swing.MigLayout;

public class AntialiacingScaleTester {

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {

                JPanel circlePanel = new JPanel() {
                    @Override
                    public void paintComponent(Graphics g) {

                        super.paintComponent(g);

                        Graphics2D g2d = (Graphics2D)g;
                        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                        g2d.setColor(Color.RED);
                        g2d.setStroke(new BasicStroke(1));
                        //g2d.drawOval(0, 0, 200, 200);
                        g2d.draw(new Ellipse2D.Double(0, 0, 200, 200));

                        AffineTransform old = g2d.getTransform();

                        g2d.setColor(Color.GREEN);
                        g2d.scale(1000, 1000);
                        g2d.setStroke(new BasicStroke(0.001f));
                        g2d.draw(new Ellipse2D.Double(0, 0, 0.225, 0.225));

                        g2d.setColor(Color.BLUE);
                        g2d.scale(10, 10);
                        g2d.setStroke(new BasicStroke(0.001f));
                        g2d.draw(new Ellipse2D.Double(0, 0, 0.025, 0.025));

                        g2d.setTransform(old);

                    }
                };

                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


                //frame.setLayout(new MigLayout("fill"));
                //frame.add(circlePanel, "w 300, h 300, grow");

                //frame.add(circlePanel);

                frame.setLayout(null);
                circlePanel.setBounds(new Rectangle(0, 0, 300, 300));
                frame.add(circlePanel);

                frame.setBounds(0, 0, 350, 300);

                //frame.pack();
                frame.setVisible(true);

            }
        });

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:11:44+00:00Added an answer on June 16, 2026 at 7:11 am

    I copy/pasted your code and it drew the 2 ellipses you wrote about, the only change I made was to replace your MigLayout by null, set the frame and panel dimensions by hand and remove the frame.pack() invocation:

    import java.awt.BasicStroke;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Test {
        /**
         * @param args
         */
        public static void main(String[] args) {
            JPanel circlePanel = new JPanel() {
                @Override
                public void paint(Graphics g) {
    
                    Graphics2D g2d = (Graphics2D) g;
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
                    g2d.setStroke(new BasicStroke(1));
                    //g2d.drawOval(0, 0, 200, 200);
                    g2d.draw(new Ellipse2D.Double(0, 0, 200, 200));
    
                    AffineTransform old = g2d.getTransform();
    
                    g2d.scale(10000, 10000);
                    g2d.setStroke(new BasicStroke(0.001f));
                    g2d.draw(new Ellipse2D.Double(0, 0, 0.025, 0.025));
    
                    g2d.setTransform(old);
    
                }
            };
    
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            frame.setLayout(null);
            circlePanel.setBounds(new Rectangle(0, 0, 300, 300));
            frame.add(circlePanel);
    
            frame.setBounds(0, 0, 350, 300);
    
            //frame.pack();
            frame.setVisible(true);
        }
    }
    

    enter image description here

    Update:
    Could reproduce the problem using the Oracle JDK (java version “1.8.0-ea”) instead of the OpenJDK. Got the diamond shape, as pointed out in another answers, the scale factor is the root cause of the shape degenaration, don’t know if that should be the appropiate behaviour though, so, there must be a bug in one these JRE’s.
    The following test program works fine for both JRE’s:

    import java.awt.BasicStroke;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class Test {
        /**
         * @param args
         */
        public static void main(String[] args) {
            JPanel circlePanel = new JPanel() {
                @Override
                public void paint(Graphics g) {
    
                    Graphics2D g2d = (Graphics2D) g;
                    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
                    g2d.setStroke(new BasicStroke(1));
                    //g2d.drawOval(0, 0, 200, 200);
                    g2d.draw(new Ellipse2D.Double(0, 0, 200, 200));
    
                    AffineTransform old = g2d.getTransform();
    
                    g2d.scale(10, 10);
                    g2d.setStroke(new BasicStroke(1.0f));
                    g2d.draw(new Ellipse2D.Double(0, 0, 25.0, 25.0));
    
                    g2d.setTransform(old);
    
                }
            };
    
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            frame.setLayout(null);
            circlePanel.setBounds(new Rectangle(0, 0, 300, 300));
            frame.add(circlePanel);
    
            frame.setBounds(0, 0, 350, 300);
    
            //frame.pack();
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the code below I am drawing a rounded rectangle. It draws a nice
Below is the code necessary to draw a rectangle. How would it be possible
The code below draws a rectangle on every mouse move after the mouse button
Hi I'm using this code below to let a user draw their signature on
I'm trying to draw the pages of a PDF using the code below. Some
I draw the ellipse with the code as shown below. How can I make
The code below fails on the line: Class.forName(oracle.jdbc.driver.OracleDriver); with the error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver The
Simple code fragment below draws an ellipse on a VB.NET panel. I now need
i'm trying to draw a rectangle with semi-circles at either end. i'm also trying
I wrote a code use CoreText layout some texts like picture below. Red rectangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.