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

Chapter 10. Swing Dialogs

In most GUI applications, certain information needs to be displayed for a brief period of time, often just long enough for the user to read it and click “OK” or perhaps enter some information, such as a username and password. In AWT, such interactions were typically carried out using the Dialog class.

As you’d probably expect if you’ve already read Chapter 8, Swing extends Dialog with a class called JDialog that implements the RootPaneContainer interface. This in itself is not a particularly exciting enhancement, though it does give you the ability to add a menu to a dialog box if you have some reason to do so.

The much more interesting new Swing feature is the JOptionPane class. This class makes creating simple dialog boxes extremely easy — in many cases requiring just one line of code. We’ll look at both of these new classes in this chapter.

The JDialog Class

JDialog is the Swing replacement for its superclass, java.awt.Dialog. It provides the same key changes described in Chapter 8,[22] in the discussion of JWindow, JFrame, and JApplet — it uses a JRootPane as its container, and it provides default window-closing behavior. Since JDialog extends java.awt. Dialog, it has a heavyweight peer and is managed by the native windowing system. Figure 10.1 shows how JDialog fits into the class hierarchy.

The JDialog class hierarchy

Figure 10-1. The JDialog class hierarchy

Properties

JDialog

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