Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame.getContentPane()

 
Fisher Daniel
Ranch Hand
Posts: 582
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to add a component into top-level container.
In here, I use JFrame as top-level container.
My understanding is there are 2 ways to do that..
1. I use JFrame method getContentPane().add(component);
2. Because of JFrame is subclass of java.awt.Containter, I can use JFrame method add(component) directly.

Is it true?
Are there performance effect between both?

thanks
daniel
 
Pat Hays
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think they are same, JFrame method add(component) will inside call getContentPane().add(component) finally. Not 100% sure.
 
Sebastiaan Kortleven
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling add() on the frame directly will give a runtime error:

java.lang.Error: Do not use add() use getContentPane().add() instead
[ November 15, 2004: Message edited by: Sebastiaan Kortleven ]
 
Ted Reynolds
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that in 1.5 they changed it so that the two methods work the same. But of course if you are working with anything from 1.2 to 1.4 you need to use the getContentPane().add().
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic