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 You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/contentpane.html J:\mindprod\jgloss\contentpane.html
logofeedback Please email your feedback for publication, 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 kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.210]
You are visitor number 51,211.