pane : Java Glossary

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:

CMP homejump to top

available 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
logo
Please email your , 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, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[23.22.252.150]
You are visitor number 25,132.