Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPanel getSize () method returns 0

843805Nov 15 2006 — edited Nov 17 2006
Hi,

I am writing a 'pong' type game which consists of a JFrame main window (using BorderLayout) with a JPanel for drawing graphics. I used netbeans to set this up.

When i call getSize () from within my class which extends JPanel, it always returns 0. I have also tried getHeight (), getWidth () etc which all return 0.

The only way i can get correct values is to call getSize () from outside the class. For example:

gamePanel.getSize () works fine but

this.getSize () or getSize () from within the class returns 0.

This is usless to me as i need to use the height and width from within my GamePanel class so i can work out co-ordinates from the size of the screen.

How can i get this to work? Can anyone help?

Many Thanks

Dan
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2006
Added on Nov 15 2006
4 comments
1,293 views