contentPane : Java Glossary

contentPane
When Swing’s JFrame class got too large it was broken into pieces. Unfortunately, the designers of Swing decided not to mask that change from the users with a facade design pattern. For some functions, such as adding a JComponent, you no longer use JFrame.add, but instead you must first get the associated Container object of the JFrame with JFrame.getContentPane(), and add to that. If you screw up, and accidentally use JFrame.add(), you won’t find out until run time, and even then the code often just quietly fails without an error message. To keep you on your toes, some Components have contentPanes and some do not. in particular JPanel does not. You add to a JPanel the some was as before.

Sun saw the error of their ways and now permits you to use JFrame. add and brethren safely in Java 1.5+. However, now you have a new problem, namely running code developed on 1.5 that works fine on 1.5+ but fails on 1.4, even when you target 1.4.

Tips

The following methods should normally be used on the contentPane, not the JFrame itself.
contentPane Methods
add
addNotify
getBackground
getFont
getForeground
getLayout
invalidate
remove
repaint
setBackground
setFont
setForeground
setLayout
setVisible
validate

CMP homejump to top

available on the web at:

http://mindprod.com/jgloss/contentpane.html
  

optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\contentpane.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[107.20.7.65]
You are visitor number 56,515.