Solved

getContentPane() ...

Posted on 2004-09-01
8
344 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 65
Books that can get me started on JAVA 2 56
count11 challenge 6 47
json format text only 4 65
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now