File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getContentPane()

 
selvas kumars
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the use of getContentPane() in swings??What difference it makes?
 
Wilfried LAURENT
Ranch Hand
Posts: 269
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, the getContentPane() allows you to get a hand on the JPanel instance contained in a JFrame. It is handy when you want to add components, because you can not add components directy to a JFrame instance.
Anyway if you try to do it, you won't get any compilation error or warning (If anybody can tell me why, I would be pleased) but a runtime error:
java.lang.Error: Do not use Toto.add() use Toto.getContentPane().add() instead
if Toto is an instance of JFrame.
W.
W.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic