aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes getContentPane()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getContentPane()?" Watch "getContentPane()?" New topic
Author

getContentPane()?

Omo Jesu
Greenhorn

Joined: Nov 30, 2010
Posts: 19
Hello All,

Saw a code in a recent textbook saying everything must be added to the contentPane before being added to the Panel. But in another recent book, I was made to know that it is not compulsory that you can easily just use the add to the frame and it gets loaded to the contentPane automatically, which I have tried and it worked. Is there any difference in both? Please explain.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4527
    
    5

Read the API for JFrame or JDialog. It's well explained there.

To get a better understanding of the role of the contentPane etc go through the API for RootPaneContainer.


luck, db
There are no new questions, but there may be new answers.
Jason Hardaway
Greenhorn

Joined: Apr 11, 2011
Posts: 26

Before JDK 5, you had to call the getContentPane() method in order to get a reference to the content pane and after that, you had to call the add() method on that reference to add the component. Now, beginning with JDK 5 and forward, it is not necessary to make an explicit call to getContentPane() because a call to add() is already routed to the content pane when add() is called on a top-level container such as JFrame. Hope this helps you.
Omo Jesu
Greenhorn

Joined: Nov 30, 2010
Posts: 19
Darryl Burke wrote:Read the API for JFrame or JDialog. It's well explained there.

To get a better understanding of the role of the contentPane etc go through the API for RootPaneContainer.


Thanks very much... Checking the RootPaneContainer API out now!

Omo Jesu
Greenhorn

Joined: Nov 30, 2010
Posts: 19
Jason Hardaway wrote:Before JDK 5, you had to call the getContentPane() method in order to get a reference to the content pane and after that, you had to call the add() method on that reference to add the component. Now, beginning with JDK 5 and forward, it is not necessary to make an explicit call to getContentPane() because a call to add() is already routed to the content pane when add() is called on a top-level container such as JFrame. Hope this helps you.


Thanks... but was confused when Head First Java said we must add to ContentPane and the book covers Java 5.0
Jason Hardaway
Greenhorn

Joined: Apr 11, 2011
Posts: 26

Omo Jesu wrote:
Jason Hardaway wrote:Before JDK 5, you had to call the getContentPane() method in order to get a reference to the content pane and after that, you had to call the add() method on that reference to add the component. Now, beginning with JDK 5 and forward, it is not necessary to make an explicit call to getContentPane() because a call to add() is already routed to the content pane when add() is called on a top-level container such as JFrame. Hope this helps you.


Thanks... but was confused when Head First Java said we must add to ContentPane and the book covers Java 5.0

You are welcome. I would assume the authors did that because some programmers may have been using an earlier version before JDK5 and they wanted to make sure the code would work for all readers.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getContentPane()?