Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2004

Tip: Looking for answers? Try searching our database.

Maximum colours in Graphics?

Thread view: 
Princess Morgiah - 06 Sep 2004 23:48 GMT
Hi everyone,

I'm faced with a rather strange problem here for which I included the source
code as a sscce.

In this piece of source code, I'm drawing a lot of ovals in a gradient
colour (blue/green), but the rightmost colours come out white even though
the colour codes are valid.

When I use fillRect, the problem does not occur.

I've also attempted to draw this picture a few dots at a time, using the
mouse (x, y minus 5 dots to plus 5 dots) and the last x dots are drawn white
wherever they are.

Increasing memory does not work, checking for exceptions turned up nothing.

Does anybody have an idea as to why I'm seeing white dots here?

--- sscce ---
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Grid extends JFrame
{

   private final int TILE_SIZE = 5;
   private final int SQ_X = 101;
   private final int SQ_Y = 101;

   public Grid()
   {
       super("Grid");
       this.setLocation(100, 100);
       this.getContentPane().setLayout(new GridLayout());
       this.getContentPane().add(new GridPanel());
       this.pack();
       this.setVisible(true);
       this.setDefaultCloseOperation(EXIT_ON_CLOSE);
   }

   public static void main(String[] args)
   {
       Grid grid = new Grid();
   }

   public class GridPanel extends JPanel
   {

       public void paintComponent(Graphics g)
       {
           g.setColor(Color.black);
           g.fillRect(0, 0, this.getWidth(), this.getHeight());

           for (int i = 0; i < 1000000; i++)
           {
               g.setColor(new Color((int) Math.random() * 100, (int)
Math.random() * 100, (int) Math.random() * 100));
           }

           for (int x = 0; x < SQ_X; x++)
           {
               for (int y = 0; y < SQ_Y; y++)
               {
                   g.setColor(new Color(0, 2 * x, 2 * y));
                   g.fillOval(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE,
TILE_SIZE);
                   // g.fillRect(x * TILE_SIZE, y * TILE_SIZE, TILE_SIZE,
TILE_SIZE);
               }
           }
       }

       public Dimension getPreferredSize()
       {
           return new Dimension(SQ_X * TILE_SIZE, SQ_Y * TILE_SIZE);
       }

   }

}
--- /sscce ---

Thanks in advance,

Princess Morgiah
Andrew Thompson - 07 Sep 2004 00:17 GMT
> I'm faced with a rather strange problem here for which I included the source
> code as a sscce.

Why is everybody looking at ..me?   ;-)

> In this piece of source code, I'm drawing a lot of ovals in a gradient
> colour (blue/green), but the rightmost colours come out white even though
> the colour codes are valid.
>
> When I use fillRect, the problem does not occur.

I am not exactly sure what you are seeing,
I did not experience the same behaviour you
described.  

With the drawOval example I saw your gradient,
with the missing bits showing as black.

When I changed to the rectangle, I got a rough
equivalent of a gradient, but as opposed to the
first exapmple, the edges of the rectangles met,
so there was no black showing though.

Could I get you to try something?  Drop the
rectangles you are drawing to half size,
then render them, see if that makes anything
click into place..

(And BTW, nice example, but could I ask
you to keep the lines shorter in future?
The lines with the drawOval/drawRect
methods wrapped..)

Lastly... is this an experiment?  
Are you familiar with GradientPaint?

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Princess Morgiah - 07 Sep 2004 23:32 GMT
> > I'm faced with a rather strange problem here for which I included the source
> > code as a sscce.
>
> Why is everybody looking at ..me?   ;-)

Hihi - I find the sscce a very useful way of solving a problem. Most times
actually creating the sscce out of a large chunk of source can solve the
problem!

> > In this piece of source code, I'm drawing a lot of ovals in a gradient
> > colour (blue/green), but the rightmost colours come out white even though
[quoted text clipped - 5 lines]
> I did not experience the same behaviour you
> described.

Well, maybe this will clear some things up: I've made two screenshots, one
with the ovals, and one with the rectangles. You can find them here:
http://www.mycgiserver.com/~holdencaulfield/grid01.jpg (170k, ovals)
http://www.mycgiserver.com/~holdencaulfield/grid02.jpg (17k, rectangles)

The grayed out border and the coordinates on screen are from the screen
capture tool, so you can safely ignore those.

> With the drawOval example I saw your gradient,
> with the missing bits showing as black.

As you can see in the screenshot, the last 200+ ovals are all white.

> When I changed to the rectangle, I got a rough
> equivalent of a gradient, but as opposed to the
> first exapmple, the edges of the rectangles met,
> so there was no black showing though.

Indeed - which is as it should be. I'm not concerned about the black edges
(which are logical given the size of the ovals), it's the white dots that
bother me.

> Could I get you to try something?  Drop the
> rectangles you are drawing to half size,
> then render them, see if that makes anything
> click into place..

Nope - that just leaves black edges, which was not the problem in the first
place. I really should have posted the link to the screenshots earlier,
sorry for that.

> (And BTW, nice example, but could I ask
> you to keep the lines shorter in future?
> The lines with the drawOval/drawRect
> methods wrapped..)

Oops - I didn't notice that... and it is indeed annoying (since I just had
to copy the code from my post to another machine because I left the source
at work).

> Lastly... is this an experiment?
> Are you familiar with GradientPaint?

This is an experiment - I'm supposed to run a test on some software in a few
days, where there are two factors that need to be monitored. I just thought
it would be nice to see them live: x, y are the factors, and the colour is
the percentage/test score: the brighter the colour, the higher the score.
The highest score would be marked in a different colour.

It wasn't supposed to be a gradient, but while writing this Grid for the
test component, I thought it would be nice to try a gradient - until I found
this error.

I am not familiar with GradientPaint, but I'll be sure to check it out -
could come in handy later on for other stuff...

Lastly, I tried this at home and at work: both machines are P4-2.x, with 512
or 768 MB RAM. It takes ages to render the ovals, and my machine even
crashed and started bothering me with messages of 'low memory' while
performing the test today... Strange...

Any ideas? Thanks for your help so far!

Regards,

Princess Morgiah
Andrew Thompson - 08 Sep 2004 00:23 GMT
> "Andrew Thompson" <SeeMySites@www.invalid> wrote in message

>>> I'm faced with a rather strange problem here for which I included the
> source
[quoted text clipped - 5 lines]
> actually creating the sscce out of a large chunk of source can solve the
> problem!

That's the ticket!  But..

> Well, maybe this will clear some things up: I've made two screenshots,

..a picture paints a thousand words!

>..one
> with the ovals, and one with the rectangles. You can find them here:
> http://www.mycgiserver.com/~holdencaulfield/grid01.jpg (170k, ovals)

Wow..  *Now* I see what you mean..  

I got none of the white area.  I even 'messed
up' your frame.  When I enlarged it, I got
grey border around the area you did not paint
(as expected) but still got the rest of the
grid reliably.  Gradient blue/green with black.

( Let me know if you want to see a screenshot. )

...hmmm.  I looked at it using 1.5.0-beta
on WinXP, what OS/Java are you using?
[ I am beginning to wonder if you've discovered
some quirky rendering bug.. ]

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Princess Morgiah - 09 Sep 2004 22:15 GMT
> > with the ovals, and one with the rectangles. You can find them here:
> > http://www.mycgiserver.com/~holdencaulfield/grid01.jpg (170k, ovals)
>
> Wow..  *Now* I see what you mean..

Indeed - I tried explaining it to a few colleagues and they were all a
little confused as to the problem, until I showed them this picture. It
really is a strange sight, and it gets even stranger if you draw the ovals
in a random order! The last x ovals always remain white...

> I got none of the white area.  I even 'messed
> up' your frame.  When I enlarged it, I got
[quoted text clipped - 3 lines]
>
> ( Let me know if you want to see a screenshot. )

Thanks for offering, but I can see what you mean - read on please...

> ...hmmm.  I looked at it using 1.5.0-beta
> on WinXP, what OS/Java are you using?
> [ I am beginning to wonder if you've discovered
> some quirky rendering bug.. ]

Well, I'm beginning to think along the same lines. I've tried it with a 1.3
which did not produce this strange problem, I haven't tried the 1.5 yet.

The problem occurs in 1.4 (early beta versions) on Windows XP (at work) and
Windows 2000 (at home).

I've been browsing through the bug database at Sun for a while and I've
found related issues, but none that are closely related. Or at least, close
enough :)

During the weekend I'll try to get to the bottom of this, as I know lack the
time for it, and then I'll post my results. Just in case someone should feel
the mad need to draw some ovals on a JPanel.

Regards,

Princess Morgiah
Andrew Thompson - 10 Sep 2004 05:15 GMT
> The problem occurs in 1.4 (early beta versions) on Windows XP (at work) and
> Windows 2000 (at home).

I suspect that is at the root of the problem.
Those early 1.4 releases were very buggy.

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.