O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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_ON_CLOSE

int

Dispose window when closed.

DO_NOTHING_ON_CLOSE

int

Do nothing when closed.

HIDE_ON_CLOSE

int

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.

JFrame

Figure 8-9. JFrame

The primary difference is that calls to add() must be replaced with calls to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required