This is a feature of JBuilder Professional and Enterprise.
The Dialog wizard creates a new class that can extend either the Dialog
class, or the JDialog
class,
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:
BorderLayout
panel to the dialog that can be designed by the UI designer. jbInit()
method in which JBuilder puts property setters and other initialization code used by the designers. The jbInit()
method will be invoked when using any of the constructors.
The wizard contains the following fields:
For more information on packages, see the "Packages" topic in the "Creating and managing projects" chapter of Building Applications with JBuilder.
//Title: Your Product Name //Version: //Copyright: Copyright (c) 1997 //Author: Your Name //Company: Your Company //Description: Your description
Creating and using dialogs
But, even without making your dialog into a bean, you can create it and use it in JBuilder.
To do this,
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, that contains a button or a menu item 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.)
actionPerformed()
event by entering a line of code inside the event handler that looks like this:
dialog1.show();
show()
method call, because show()
doesn't return until the modal dialog is dismissed. You can use a result
property to determine whether the OK or Cancel button was pressed.
show()
returns immediately. Because of this, the dialog class itself will need to expose events for each of the button presses. When using the dialog, you will need to register listeners to the dialog's events, and place code in the event handling methods to use property getters to get the information out of the dialog.
To see examples of using modal dialog components (dialogs that have been wrapped as Beans, with default constructors), see the tutorial, "Building a Java text editor."