Computer Science Canada JFrame.setVisible(true) is causing an error? |
| Author: | Benner [ Fri Apr 19, 2013 10:16 pm ] | ||||
| Post subject: | JFrame.setVisible(true) is causing an error? | ||||
Hi, I finally pinpointed where my error was coming from in my code. I'm not sure if this error is causing any problems in my program as it's not complete yet but It would be nice to figure out why this is happening. the code I have is:
The error I get is: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.TimSort.mergeLo(TimSort.java:747) at java.util.TimSort.mergeAt(TimSort.java:483) at java.util.TimSort.mergeCollapse(TimSort.java:410) at java.util.TimSort.sort(TimSort.java:214) ...this goes on for a hundred or so lines. No where in the (stack?) is there anything to do with code in my project. TimSort is part of the java.util package. Any help into why this happens would greatly be appreciated. Thanks Full Code: (line that gives the error is at the bottom)
|
|||||
| Author: | DemonWasp [ Fri Apr 19, 2013 10:40 pm ] | ||
| Post subject: | RE:JFrame.setVisible(true) is causing an error? | ||
In the future, when you have a problem in Java, always post the stack trace in code blocks:
I'm not a Swing/AWT expert, but it looks like you hit some bug that's caused by having WAY WAY WAY too many GUI elements. You're trying to add 70 * 115 = 8050 elements to EACH of three spots, which is just way too many (and, clearly, more than SUN/Oracle ever tested for). If you reduce "width" and "height" to values like 5 and 7, then the error vanishes and your program works (or, at least, it looks like it does...I can't tell because I don't know what it's supposed to do). The reason that removing setVisible(true) causes the error to disappear is because the error occurs when Swing/AWT tries to draw your panel, which doesn't happen if you never show it. As for how to get 8000+ "cells" to appear, try using the advice I gave you in your other thread: http://compsci.ca/v3/viewtopic.php?t=33591 |
|||
| Author: | Benner [ Fri Apr 19, 2013 10:48 pm ] |
| Post subject: | Re: JFrame.setVisible(true) is causing an error? |
You're right, the problem was having that many elements With your suggestion by drawing the cells on the jpanel, would I be able to change the colour of each cell (like what is done in http://youtu.be/XcuBvj0pw-E?t=1m5s)? If so, don't worry about explaining more about it to me, I'll do research on it. Thanks again |
|
| Author: | DemonWasp [ Fri Apr 19, 2013 11:05 pm ] |
| Post subject: | RE:JFrame.setVisible(true) is causing an error? |
Yes, you can. You could even draw images or more complicated shapes than just rectangles. The Oracle tutorial on how to use the Graphics and Graphics2D objects aren't bad: http://docs.oracle.com/javase/tutorial/2d/ |
|
| Author: | Benner [ Fri Apr 19, 2013 11:17 pm ] |
| Post subject: | Re: JFrame.setVisible(true) is causing an error? |
Thank you! |
|