pane : Java Glossary
home P words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : 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)
pane
These really should be called pains since they cause so many bugs. With Swing, the JFrame class got so large and complicated, it was split into several classes. You would have expected that the designers of Swing would hide the fact that JFrames are actually several objects by using the Decorator design pattern. However, they decided not to. You must deal with the pieces called panes individually, and direct you methods to the appropriate object. It is very easy to use the wrong piece, and often the compiler will not detect the error. The most common errors are to use Jframe.setLayout or jframe.add instead of contentPane.setLayout and contentPane.add or to use Jframe.setBackground or jframe.setForeground instead of contentPane.setBackground and contentPane.setForeground.

However, Sun has relented somewhat in Java 1.5. You can add to the JFrame and it is treated as if you added to the correspoding contentPane. Be aware of that when debugging code under 1.5 that you also want to run under 1.4 that that code won’t work.

Not only does JFrames use panes, so does JApplet, JDialog, JInternalFrame and JWindow but not JPanel.

Note there is no Pane, JPane, ContentPane or GlassPane class.

Pieces of a JFrame
Name What Is It For? How Created Methods
JFrame Master object for the frame. Automatically creates the other pieces.
JFrame jframe = new JFrame();
getContentPane
getGlassPane
getRootPane
invalidate
setBackground
setFont
setForeground
setVisible
validate
ContentPane
(Container)
keeps track of the Components contained in the JFrame or JApplet.
Container contentPane = jframe.getContentPane();
add
remove
setBackground
setForeground
setLayout
DesktopPane A type of LayeredPane where the JinternalFrames live, covering up the JFrame contents, free to move around anywhere inside the JFrame.
DesktopPane d = new DesktopPane();
d.add( anInternalFrame );
jframe.setLayeredPane( d );
DesktopPane.add( child, JLayeredPane.DEFAULT_LAYER );
remove
setSelectedFrame: select which JInternalFrame is the active one.
setBounds: it is up to you to size and position everything. There is no layout mananager.
setLayer(Component c, int layer, int position) to place a component on a layer and at a depth Z position within that layer.
LayeredPane LayeredPanes allow you to place JComponents on top of one another. The LayeredPane is further subdivided into five layers: default, palette, modal, popup and drag.
LayeredPane layeredPane = frame.getLayeredPane();
LayeredPane.add( child, JLayeredPane.DEFAULT_LAYER );
remove
setBounds: it is up to you to size and position everything. There is no layout mananager.
setLayer(Component c, int layer, int position) to place a component on a layer and at a depth Z position within that layer.
GlassPane
(Component)
A transparent canvas overlaying the contentPane. You use it typically for sprite animations. You do much of your drawing with colours with alpha channel values not = 0xff, to allow the contentPane to show through. I have not yet experimented to discover how its co-ordinate system meshes with the content pane’s. GlassPanes are also used to intercept mouse events for the frame.
Component glassPane = jframe.getGlassPane();
Note, the glassPane is a lowly Component, not a Container or JComponent. All you can do is draw on it. You can’t add Components to it.
paint
JRootPane deals with the decoration around the outside of the frame.
JRootPane rootPane = jframe.getRootPane();
setJMenuBar
setWindowDecorationStyle

Learning More

Sun’s Javadoc on the JFrame class : available:

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.16] The information on this page is for non-military use only.
You are visitor number 14,370. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/pane.html J:\mindprod\jgloss\pane.html