Basic RootPaneContainers
For the rest of this chapter,
we’ll look at some basic containers (JFrame,
JWindow, and JApplet) that
implement RootPaneContainer and use
JRootPane. First, we’ll take a quick look at
a simple interface called WindowConstants.
The WindowConstants Interface
WindowConstants is
a simple interface containing only constants. It is implemented by
JFrame, JDialog, and
JInternalFrame.
Constants
The constants defined in WindowConstants specify
possible behaviors in response to a window being closed. These values
are shown in Table 8.6.
Table 8-6. WindowConstants Constants
|
Constant |
Type |
Description |
|---|---|---|
|
|
|
Dispose window when closed. |
|
|
|
Do nothing when closed. |
|
|
|
Hide window when closed. |
In the next section, we’ll look at a strategy for exiting the application in response to a frame being closed.
The JFrame Class
The most common Swing container for Java
applications is the JFrame. Like
java.awt.Frame, JFrame provides
a top-level window with a title, border, and other platform-specific
adornments (e.g., minimize, maximize, and close buttons). Because it
uses a JRootPane as its only child, working with a
JFrame is slightly different than working with an
AWT Frame. An empty JFrame is
shown in Figure 8.9.

Figure 8-9. JFrame
The primary difference is that calls to add() must be replaced with calls to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access