contentPane : Java Glossary

go to home page C words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish 2008-02-06 by Roedy Green ©1996-2009 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (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

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.62] Environmental holiday cards that actually help the environment
You are visitor number 30,513.
You can get a fresh 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