Solved

getContentPane() ...

Posted on 2004-09-01
8
363 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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