JPanel getSize () method returns 0
843805Nov 15 2006 — edited Nov 17 2006Hi,
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