Solved

getContentPane() ...

Posted on 2004-09-01
8
358 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 92
table example 4 29
What's wrong with this code? 4 23
CSV file parsing thru Java 13 31
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

810 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