A wizard is a step-by-step assistant that helps the user to enter information in a structured manner.
NetBeans offers the developer the option to create a wide variety of wizards. These wizards can be non-sequential in nature, further enhancing the user experience.
To create a NetBeans Module follow the steps below:
NBCookbookWizard
and leave all the default values as they are and click Next >. com.packtpub
.Now with the project created, perform the following steps to create the wizard:
Now let's modify FirstWizardAction.java
, replacing the following line:
wizardDescriptor.setTitle("Your wizard dialog title here");
with this:
wizardDescriptor.setTitle("Project Wizard");
Then save the file.
Now to add components to our panel. Open FirstVisualPanel1.java
and add the following Swing components:
getName()
method replace the String Step #1 with Name and Location.Open FirstVisualPane2.java
and add the following Swing components:
Replace the default text of the first Label with Description, and the text of the second Label with Type.
Click on the first RadioButton and on the Properties window (on the right side of the IDE) under the Other Properties sub-section replace the text in the Label property with Web.
Do the same thing to the second RadioButton, but this time under Label enter Desktop.
Now click on the Source button and on the getName()
method replace the String Step #2 with Project Description, then the file. And finally the last FirstVisualPane. Open FirstVisualPane3.java
and add the following Swing components:
On the right-hand side of the property there is a button with three dots (…) that will let the developer replace the text with the following:
Now click on the Source button and on the getName()
method replace the String Step #3 with Servers. Click OK and save the file.
Open layer.xml
and replace the following code:
<filesystem/>
with
<filesystem> <folder name="Toolbars"> <folder name="File"> <file name="com-packtpub-FirstWizardAction.shadow"> <attr name="originalFile" stringvalue="Actions/File/com-packtpub-FirstWizardAction.instance"/> </file> </folder> </folder> <folder name="Actions"> <folder name="File"> <file name="com-packtpub-FirstWizardAction.instance"> <attr name="delegate" newvalue="com.packtpub.FirstWizardAction"/> <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/> </file> </folder> </folder> </filesystem>
Save the file and click on Run.
When Generate XML Layer is selected NetBeans creates the layer.xml
file in the specified directory (which can be changed depending on preference).
The layer.xml
file registers our component to NetBeans, in our case a new wizard will be added to the toolbar.
On the New Wizard dialog on the Wizard type step we have selected Registration Type as Custom so that the user will have a sequential progress in each wizard step.
Selecting Custom as Wizard Type also has an effect on which files NetBeans will create for arranging the wizard.
The files created by NetBeans for the wizard are:
FirstWizardAction.java:
responsible for registration and behavior of the component as a whole.FirstVisualPanelX.java:
one created for each of the panels. X can be replaced by the number of selected panels. It is where the wizard is designed and other components, like labels and textfields are placed.FirstWizardPanelX.java:
as with FirstVisualPanel.java
, one is created for each panel. This is where data that was entered in the Visual Panels is then retrieved and stored so that it can be available to the wizard action.This is also an easier and faster way to create wizards other than fiddling around with combinations of Registration Types and Wizard Step Sequence.
For the Wizard Step Sequence option we went for keeping things simple and selecting the Static option. This prevents the wizard user this will prevent it from "jumping" between wizard panels giving a more linear progress which might give a more restrictive experience. For the developer it means easier way to implement it, since the developer wont need to keep track of all possible combinations.
After saving and running the files the results should look like this: FirstVisualPanel1.java
.
Implementing another kind of wizard. Also, how to add your own icon to the toolbar.
There are other ways the wizard can be created that will result in different interactions with the user and vary the amount of work/flexibility involved.
On the second step of the New Wizard dialog, the Wizard type, choose Registration Type as Custom and Wizard Step Sequence as Dynamic.
This new wizard will provide the functionality of jumping between panels. This will provide more flexibility to the user but with the added expense to the developer that will be forced to handle the non-linear progression between panels.
The file list is almost the same as the one we have seen in the recipe example. The difference being that now we will have the WizardIterator.java,
which is created to handle these panel changes.
The file list is also almost identical to the previous examples but with the notable addition of an HTML file which is responsible for holding the description of the wizard itself.
As with the previous example, the WizardIterator is responsible for providing the directions that the wizard will take.
Notice that when running our example there is no default icon for the placeholder of our new wizard. NetBeans uses a missing icon image as the default one.
To add an icon follow the steps below:
layer.xml
.<file name="com-packtpub-FirstWizardAction.instance">
</file>
tag add (Supposing our image is named as picon.png):
<attr name="iconBase" stringvalue="com/packtpub/picon.png"/>
src/com/packtpub
.18.222.120.200