Dialog Wizard

The Dialog Wizard creates a new class that extends Dialog and adds it to the current project. It adds header information to the class from the project file and adds the necessary import statements. It also does the following:

To open the Dialog Wizard, choose File|New, then double-click the Dialog icon.

The wizard contains the following fields:

Package

Displays the package name derived from the project file. To assign a different package name to the file, click in the Package field and type in the new name.

For more information on packages, see the Packages topic in the "Creating and managing projects" chapter of Getting Started with JBuilder.

Name of new JavaBean

Displays the default name assigned to the class. To rename the class, click in the Class Name field and type in a new name.

Base class to inherit from

Displays a drop-down list box to select the class from which you want to inherit.

Show only core JDK and Swing classes

Restricts the choices on the "Base class to inherit from" drop-down list to the JDK and Swing classes.

See also:
Creating and using dialogs


Creating and using dialogs

When making a new dialog, you should consider whether you want to make it into a Java Bean that can be placed on the Component Palette. If so, there are specific additional requirements that you must consider. For more information, see "Making a dialog box a JavaBean" in the Component Writer's Guide.

But, even without making your dialog into a bean, you can create it and use it in JBuilder.

Creating a new dialog

To create a new dialog, use the Dialog Wizard. After finishing the wizard, you can design the panel that was placed in the new dialog class using the UI Designer. This is how you add buttons and other controls to your new dialog.

Even if you are not initially making your dialog into a bean, you will find useful information in the topic "Making a dialog box a JavaBean" in the Component Writer's Guide. This topic expains how to add properties and events to your dialog, such as properties for result codes and user entered values, and aggregated events for buttons.

Using a dialog that is not a bean

Once the dialog has been created and its UI designed, you will want to test or use your dialog from some UI in your program. Here is a way to do this:

  1. Instantiate your dialog class from someplace in your code where you have access to a Frame which can serve as the parent Frame parameter in the dialog constructor. A typical example of this would be a Frame whose UI you are designing, which contains a Button or a MenuItem which is intended to bring up the dialog. In applets, you can get the Frame by calling getParent() on the applet.

    For a modeless dialog (which we are calling dialog1 in this example), you can use the form of the constructor that takes a single parameter (the parent Frame) as follows:

       Dialog1 dialog1=new Dialog1(this);

    For a modal dialog, you will need to use a form of the constructor that has the boolean modal parameter set to true, such as in the following example:

       Dialog1 dialog1=new Dialog1(this, true);

    You can either place this line as an instance variable at the top of the class (in which case the dialog will be instantiated during the construction of your Frame and be reusable), or you can place this line of code in the actionPerformed event handler for the button that invokes the dialog (in which case a new instance of the dialog will be instantiated each time the button is pressed.) Either way, this line instantiates the dialog, but does not make it visible yet.

    (In the case where the dialog is a bean, you must set its frame property to the parent frame before calling show(), rather than supplying the frame to the constructor.)

  2. Before making the instantiated dialog visible, you should set up any default values that the dialog fields should display. If you are planning to make your dialog into a Bean (see below), you need to make these dialog fields accessible as properties. You do this by defining getter and setter methods in your dialog class. See the Component Writers Guide for more information.

  3. Next, you have to cause the dialog to become visible during the actionPerformed event by entering a line of code inside the event handler that looks like this:
       dialog1.show();

  4. When the user presses the OK button (or the Apply button on a modeless dialog), the code that is using the dialog will need to call the dialog's property getters to read the user-entered information out of the dialog, then do something with that information.

To see examples of using modal dialog components (dialogs that have been wrapped as Beans, with default constructors), see the TextEdit tutorial in Getting Started with JBuilder in the Quick Start.