Solved

getContentPane() ...

Posted on 2004-09-01
8
398 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
Technology Partners: 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!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

632 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