Chapter 9. Internal Frames

Managing a Desktop

Certain GUI applications need to simulate a desktop environment by allowing multiple “frames” to be displayed within a single root window. These frames look like the normal frames you’d see on a real desktop, but are not actually known to the window manager, because they are not really windows in the normal sense of the term. For some types of applications (word processors, IDEs, etc.), this can be a very powerful approach to UI design.

In this chapter, we’ll look at a collection of classes Swing provides to allow you to create this type of application in Java. At the end of the chapter, we’ll provide a large sample program that shows how to implement a variety of useful features.

Overview

Before looking at each of the classes involved in the Swing desktop/internal frame model, we’ll take a moment for an overview of how they all work together. Figure 9.1 shows the relationships between the classes we’ll be covering in this chapter.

Internal Frame and Desktop class diagram

Figure 9-1. Internal Frame and Desktop class diagram

A JInternalFrame is a container that looks much like a JFrame. The key difference is that internal frames can only exist within some other Java container. JInternalFrame implements the following three interfaces: Accessible, WindowConstants, RootPaneContainer.

Each internal frame keeps a reference to an instance of the static inner class called JDesktopIcon ...

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.