Results 1 to 4 of 4
  1. #1
    Cyorxamp is offline Member
    Join Date
    Jun 2008
    Posts
    23
    Rep Power
    0

    Question Java Drawing PUZZLE

    Lo folks,

    First post here, I'm going to share a puzzle with you about the AWT Graphics fillArc method that I'm experiencing.

    Basically I like little borders like this on my custom JPanels before sticking components in it...



    That shot was taken on my Linux box, however when I load it on Windows the arcs are drawn differently. I've colour coded the seperate bits I draw and shown the top corner bits of the box below zoomed in (the grey border is extra for this shot)...



    The top ones are Windows, bottom ones are Linux.

    Here is the code I use (in a paintComponent override) to make them...

    Java Code:
    Dimension dmnSize = getSize();
    gpxGraphics.fillArc(4, 4, 35, 35, 180, -90);
    gpxGraphics.fillArc(dmnSize.width-40, 4, 35, 35, 90, -90);
    Is Java meant to be controlling how a arc/circle is drawn, or is the host OS meant to be controlling this?

    Any ideas on how to get a consistant look on both?

    Thanx in advance...

    Steve

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I can't answer for the differences between Java's rendering of these graphics in different OS environments, but have you considered setting your rendering hints to turn on anti-aliasing in order to get rid of the "jaggies"?

  3. #3
    Cyorxamp is offline Member
    Join Date
    Jun 2008
    Posts
    23
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I can't answer for the differences between Java's rendering of these graphics in different OS environments, but have you considered setting your rendering hints to turn on anti-aliasing in order to get rid of the "jaggies"?
    Any idea what method I should be calling to do that? I looked in java.awt.Graphics and can't see anything.

    Also (to all) apart from using an image (which would be cheating) is there anything else in the normal Java API for drawing these curves?

  4. #4
    Cyorxamp is offline Member
    Join Date
    Jun 2008
    Posts
    23
    Rep Power
    0

    Default

    In converting to an anti aliased mode I swapped to Graphics2D... and in doing so it was drawing the 'Windows' way whether on Windows or not but at least it was anti aliased. So I adjusted the x and y values and it shows correcly and anti aliased on all platforms now...

    Code..

    Java Code:
    @Override
        public void paintComponent(Graphics gpxGraphics)
        {
            super.paintComponent(gpxGraphics);
            Graphics2D g2dGraphics = (Graphics2D)gpxGraphics;
            g2dGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            //Find the size of the panel
            Dimension dmnSize = getSize();
            //Set pen to black
            g2dGraphics.setColor(Color.BLACK);
            //Draw left and right curved edge
            g2dGraphics.fill(new Arc2D.Double(5, 5, 35, 35, 180, -90, Arc2D.PIE));
            g2dGraphics.fill(new Arc2D.Double(dmnSize.width-40, 5, 35, 35, 90, -90, Arc2D.PIE));
            //Draw title block
            g2dGraphics.fill(new Rectangle(22, 5, dmnSize.width-44, 17));
            //Draw left and right border
            g2dGraphics.fill(new Rectangle(5, 24, 2, dmnSize.height-31));
            g2dGraphics.fill(new Rectangle(dmnSize.width-7, 24, 2, dmnSize.height-31));
            //Draw top and bottom border
            g2dGraphics.fill(new Rectangle(5, 22, dmnSize.width-10, 2));
            g2dGraphics.fill(new Rectangle(5,dmnSize.height-7, dmnSize.width-10, 2));
        }
    }
    Thanks for the help guys!

Similar Threads

  1. drawing window
    By BlitzA in forum New To Java
    Replies: 1
    Last Post: 01-15-2009, 01:55 PM
  2. Help with drawing strings!
    By JavaInLove in forum AWT / Swing
    Replies: 1
    Last Post: 02-05-2008, 04:39 AM
  3. drawing window
    By BlitzA in forum Advanced Java
    Replies: 0
    Last Post: 12-30-2007, 06:39 PM
  4. Drawing outside paintComponent()
    By DarkSide1 in forum Java 2D
    Replies: 2
    Last Post: 11-08-2007, 11:36 PM
  5. Help with Drawing a line
    By Rgfirefly24 in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •