Methods of Dialogs

Since Dialog and Frame are both subclasses of Window, they share many methods including setLocation() and setSize(). The only methods that are significantly different between a dialog and a frame are the constructors. The constructors for Dialog all provide a parent window (which must be non-null) and some have an option to set modality:

public Dialog(Frame owner)
public Dialog(Frame owner, boolean modal)
public Dialog(Frame owner, String title)
public Dialog(Frame owner, String title,  boolean modal)

There are several more constructors, but this will be enough for us for now.

For example,

Dialog d = new Dialog(someFrame, false);

The modal argument specifies whether or not the dialog should be modal. If it should be, pass true. If it shouldn't be, pass false.

There are also some common differences between most frames and most dialogs, but these are not written in stone:

  1. Most frames can be moved and resized by the user. Most dialogs cannot be.
  2. Most frames have title bars. Most dialogs do not.

You can make a dialog resizable and movable by calling its setResizable() method with a boolean value of true like this:

d.setResizable(true);

You can give a dialog a title bar by adding the title string to the constructor:

Dialog d = new Dialog(parentFrame, "My Dialog Window", false);

All the other methods of the Dialog class are exactly the same as they are for Frames. You resize them the same way. You move them the same way. You make them visible the same way. You add components to them the same way.


Previous | Next | Top | Cafe au Lait

Copyright 1997, 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 27, 2002