Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie question on content pane  RSS feed

 
Sven Thor
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a textbook on Java I am using the author claims that components can be added directly to a frame (JFrame) instead of adding them to the content pane of the frame. The only example provided when one needs to use the content pane is when setting the background (setBackground()).

However, this is not in agreement with the API documentation from Sun which claims:
"The content pane provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame."

Which one should one follow ? And when does it matter ?

Br,
SvenT.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pre Java 5(1.5) you can only add components to a JFrame's contentPane. You could do getContentPane().add(Component) or you could do something like Container = getContentPane(). Normally though you would add another container like a JPanel to the JFrame's contentPane or set a seperate container as the JFrame's contentPane via setContentPane(myContainer).

As of Java 5(1.5) they finally changed JFrame's add method so that it looks something like:



That way you don't have to explicitly getContentPane to add something to a JFrame anymore. Not sure if this answers your question exactly, but it is the way it is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!