contentPane : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

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

This page is posted
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
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[3.144.4.50]
You are visitor number