• Post Reply Bookmark Topic Watch Topic
  • New Topic

with getContentPane() or not  RSS feed

 
Hui Zhao
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am shame to ask this simple question.
I forgot the concepts for a longer time.
I need somebody to knock my head reminding me.

On the above code, please notice if we switch the code

into

The results are same. Why?

Thanks
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before Java 5.0, you had to use getContentPane() to set the layout and add/remove components. This was because the frame / dialog / window itself has other internal components - like the content pane. Setting the layout or adding components would mess up the entire look of the frame / dialog / window.

Now in Java 5.0, they have overridden the setLayout and component related methods to redirect to the content pane. So the code for add is something like this:


To be honest, I never use these methods but always use getContentPane. I write both Java 6 and Java 1.4 code, so this way I'll never use the wrong methods when I'm busy with Java 1.4.
[ January 15, 2008: Message edited by: Rob Prime ]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!