Solved

getContentPane() ...

Posted on 2004-09-01
8
385 Views
Last Modified: 2010-05-18
Hi Experts,

    I am reading the JFrame in the Sun java tutorial. I saw JFrame has the following function :
   
    getContentPane() :  Returns the contentPane object for this frame.

    I don't know what "contentPane" is ... and I can not find the "contentPane" class or container it in the tutorial ....... could anyone please give me some directions ? Thanks a lot !

 meow.
0
Comment
Question by:meow00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11949896
contentpane is the container that you add components to.
it is a Container.
0
 
LVL 92

Expert Comment

by:objects
ID: 11949904
ie. you don't add components to the frame, you instead add them to the content pane.

eg.

Container pane = frame.getContentPane();
pane.setLayout(new FlowLayout());
pane.add(new JLabel("X"));
0
 
LVL 92

Expert Comment

by:objects
ID: 11949913
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 1

Author Comment

by:meow00
ID: 11949928
Thanks .... so is it true that : in the

 "pane.setLayout(new FlowLayout());
  pane.add(new JLabel("X")); "

 we still use JFrame method setLayout() and add(), even though they are invoked by a pane rather than a frame ?

  thanks !

0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 30 total points
ID: 11949947
No, you use the Container setLayout() and add() then
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 50 total points
ID: 11949953
No, you are setting the layout of the bit of the frame that contains components...

You can't call JFrame.setLayout() or JFrame.add, as JFrame cannot contain components, or have a layout... that is the job of the content pane...

Think of the JFrame as the window border, and the title bar, and the close/minimise/maximise icons, and the contentPane as the bit that contains all of the controls...
0
 
LVL 92

Accepted Solution

by:
objects earned 220 total points
ID: 11949955
> we still use JFrame method setLayout() and add(), even though they are invoked by a pane rather than a frame ?

No, in fact you'll get an error if you do.
you should add your components to the content pane.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11950019
Thank you
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
iterator/ListIterator approach 17 68
Running JavaFX on JDeveloper 12C 1 116
Tagging and Merging on Branch 1 70
import as existing maven project 3 78
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question