pane : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (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 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 coordinate 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

Oracle’s Javadoc on JFrame class : available:

This page is posted
on the web at:

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

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

J:\mindprod\jgloss\pane.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.139.93.242]
You are visitor number