File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Sprites disappearing after scaling down window? Aaargh the frustration! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sprites disappearing after scaling down window? Aaargh the frustration!" Watch "Sprites disappearing after scaling down window? Aaargh the frustration!" New topic
Author

Sprites disappearing after scaling down window? Aaargh the frustration!

Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
I am so stumped here!

Ok, so I have a chess program that I am writing, and I can't for the life of me figure out what is wrong with my resize code. Any help is greatly appreciated!

EDIT: See 2 comments below for a short compilable example.

Problem: Every time I resize the window smaller, certain pieces disappear, however this problem only arises when I resize the window fast. If I gradually resize it smaller, the pieces don't disappear!?!? I have attached images of the problem.

Code Structure: The resize code is spread over 3 classes. The MainGui, the ChessBoard, and the ChessPiece class. The gamePanelComponentResize method resides in the MainGui class, and is a listener for the resize component event. This method then delegates the resize order to the ChessBoard object, which in turn delegates it to each of the remaining ChessPiece objects.

MainGui method:


ChessBoard Methods:




ChessPiece methods:



[Thumbnail for maximized.png]


[Thumbnail for minimized.png]


[Thumbnail for startup.png]

Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I can't see no classes and no relations. If you could dumb down your problem to a SSCCE ... that would be great.


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
Ok, I will trim down the fat and try to get a simple compilable example ready by the end of today.
Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
Heres a simple compilable example of the problem. I apologize for the length of ChessBoard.java. Most of the code in that class is initialization code and can be ignored. The resizeBoard, setSize, and paintComponent methods are the only ones linked to the problem (that I'm aware of) in that class.

Thank you for taking the time to help!

MainGui.java


ChessBoard.java


ChessPiece.java


ChessSquare.java



[Thumbnail for board.png]


[Thumbnail for wpawn.png]

Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
Any idea's guys? I'm thinking it might be thread related, however if I spawn a new thread each time the resize event is called, won't it be flooded with duplicate threads, all doing the same thing but with different size variables? Any thoughts?
Thanks guys!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Tyler Eastman wrote:Any idea's guys? I'm thinking it might be thread related, however if I spawn a new thread each time the resize event is called, won't it be flooded with duplicate threads, all doing the same thing but with different size variables? Any thoughts?
Thanks guys!


I've been looking at this, and I'm not sure, but I don't think that it's thread related, but much of the problem is that I can't see where the problem is since it is how Swing is calling your paint methods. The error occurs when the view is shrunk quickly, and when this happens, Swing doesn't paint all the components in the container (at least I'm not seeing the output from a println I have in a paintComponent displaying from all the components when this happens). As an aside, you know that you can and should simplify your code greatly by using arrays here.
Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
Thanks for your fast response Pete! I will condense the piece initialization and resize code down using arrays once I'm at my home computer tomorrow, I can see how not using them adds unnecessary bulk to the example.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
I think I'd simply use a GridLayout, there shouldn't be painting problems at all using the 'standard' layout managers. Animations could always be drawn 'on top' (e.g. on a glasspane).

Tyler Eastman
Greenhorn

Joined: Jan 02, 2010
Posts: 7
Thank you so much Peter, your example seems to have solved the problem completely! It will require me to restructure my animation code a little bit, but after pulling my hair out for 2 weeks on the resize code, it will be a welcome change of pace!

Thank you everyone for your help, it is very appreciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sprites disappearing after scaling down window? Aaargh the frustration!
 
Similar Threads
chess game : moving piece
Queen 8 ChessBoard Example Help
Chessboard-Newbie Question
display image in jpanel
Graphics?????