Beyond Buttons

Buttons are very useful, but even with great images forming the buttons, they still lack a certain glamour—every application has buttons. For the next example, let’s take a look at something a bit more exciting. (Well, exciting might be a bit of an exaggeration, but it definitely has more impact than buttons.) The Swing package contains a new class called JInternalFrame , which allows you to create free-standing frames with menus, titlebars, and everything else a Frame needs right inside your application.

What Is an Internal Frame?

Before we start coding, here’s a brief rundown of the features of an internal frame:

  • Same functions as a normal Frame object, but confined to the visible area of the container it is placed in

  • Can be iconified (icon stays inside main application frame)

  • Can be maximized (frame consumes entire main application frame area)

  • Can be closed using the standard controls for popup windows

  • Can be placed in a “layer,” which dictates how the frame displays itself relative to other internal frames (a frame in layer 1 can never hide a frame in layer 2)

Figure 2.6 shows a simple internal frame using the Metal L&F.

The SimpleInternalFrame application using the Metal look-and-feel

Figure 2-6. The SimpleInternalFrame application using the Metal look-and-feel

For this first example, we’ll add an empty internal frame to an application. Once that’s working, we’ll expand the simple frame to create a couple of different types of internal ...

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.