Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2008, 02:31 PM
Member
 
Join Date: Jun 2008
Posts: 23
Cyorxamp is on a distinguished road
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...

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-07-2008, 03:56 AM
Senior Member
 
Join Date: Jun 2008
Posts: 426
Fubarable is on a distinguished road
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"?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-07-2008, 04:10 PM
Member
 
Join Date: Jun 2008
Posts: 23
Cyorxamp is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-09-2008, 11:35 AM
Member
 
Join Date: Jun 2008
Posts: 23
Cyorxamp is on a distinguished road
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..

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!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with drawing strings! JavaInLove AWT / Swing 1 02-05-2008 04:39 AM
drawing window BlitzA Advanced Java 0 12-30-2007 06:39 PM
drawing window BlitzA New To Java 0 12-30-2007 05:45 PM
Drawing outside paintComponent() DarkSide1 Java 2D 2 11-08-2007 11:36 PM
Help with Drawing a line Rgfirefly24 New To Java 1 08-06-2007 09:40 AM


All times are GMT +3. The time now is 11:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org