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 ...
Get Java Swing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.