Question:
java error, please help?
anonymous
2012-06-21 04:03:54 UTC
Container c=getContentPane();
throws an error, cannot find the symbol method getContentPane(); still i have imported awt package.
please fix the error.
Three answers:
Nithya
2012-06-21 04:21:12 UTC
To begin with Swing made you use getContentPane() for things like add() and setLayout() to make you realize that there were different layers. After a while I guess they conceded that it was a pain so they had the getContentPane() called internally so you didn't have to anymore.



This was changed in JDK 1.5:



Lastly, after seven years, we've made jFrame.add equivalent to jFrame.getContentPane().add()
husoski
2012-06-21 12:42:01 UTC
Are you using that in an instant method of something that derives from JFrame or JApplet? If not, then then you need a reference to whichever of those you're using. As in:



Container c = myFrame.getContentPane(); // or...

Container c = theApplet.getContentPane();



Your statement, without an object reference, is using the implied (this) object. A static method has no (this) object, and an instance of a class that doesn't derive from JFrame or JApplet probably doesn't have a getContentPane() method.
James Bond
2012-06-21 11:07:32 UTC
Try importing javax.swing.*;


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...