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.getHeight() or getWidth returning 0?

843806Aug 10 2009 — edited Aug 10 2009
I am not sure why they are doing that. I initially set the size of the panel to a specific height and width, wouldn't get height and get width return that height or width? My code is below...
gameWindow()
	{
		super(); 
		JButton button = new JButton("start");
        JFrame f = new JFrame("Missle Command, Part Duex!");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
        f.getContentPane().add(getUIPanel(), "Last");
		f.addMouseListener(new pointsListener());
        f.setSize(500,800);
        f.setLocation(200,200);
        f.setVisible(true);
		f.add(this);
.
.
.
}
This code returns 0...
public city(JPanel thePanel, int pos, int pos2)
	{
		//constructor
		double gameXX = thePanel.getWidth();
		double gameXY = thePanel.getHeight();
		System.out.println("The height and x Position of the Variables "+gameXX+" " +gameXY);//<-I get zero when I print this.  Strange!

.
.
.
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 7 2009
Added on Aug 10 2009
4 comments
2,912 views