Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Creating Wizard Dialogs with Java Swing

Wizard dialogs are ubiquitous in today's desktop applications. This article creates a framework for a simple wizard dialog, complete with Back, Next, and Cancel buttons that you can extend for use in your applications as necessary.

Tutorial Details:

Wizard dialogs are ubiquitous in today's desktop applications. What exactly is a wizard dialog? Well, you've likely run across several wizard dialogs already, either when you're installing a pre-packaged application, or you're configuring a series of program options. In this article, I will create a framework for a simple wizard dialog that you can extend as necessary.

A wizard dialog is constructed with a number of panels, and each panel contains user-configurable components such as radio buttons, sliders, or text fields. The idea here is that the application user, by pressing either the Next or Back buttons, can "flip" across these panels, entering information on each one until he or she completes the path. At this point, the Next button often changes to a Finish button, and when pressed, the dialog will close. The instantiating class should then be able to retrieve all of the data that was entered. At any time, the user can also press the Cancel button to quit the dialog and discard any data that has been entered so far.

Seems like a simple design, right? Well, not necessarily. Here are a few design considerations that must be kept in mind.

First, note that wizard dialogs do not necessarily traverse across their panels in a linear fashion. In other words, if a wizard dialog has Panels 1 through 5, pressing the Next button four times may take you from Panel 1 to Panel 5, traversing across Panels 2, 3, and 4. But that's not always the case. For example, what happens if Panel 3 tries to connect to a remote server and cannot make the connection? In that case, the wizard may need to branch off to another series of panels which takes the user through a setup without connecting to the server. And when you add several possible such branches into the equation, you begin to see that wizard panels must be connected in a tree-like fashion, where you start at the beginning (the trunk) and move your way down branches until you reach a terminable leaf, at which point the Next button should change to a Finish and the wizard dialog ends.


Second, the Next and Back (and even sometimes the Cancel) buttons may need to be disabled. At the initial panel, the Back button should always be disabled - after all, there's no previous panel to go back to. However, there are other cases where the Next button should be disabled. Validating user entry is the traditional example of this. Let's say that a panel is asking a user to enter their password twice using two Swing JPasswordField components. (This sort of password entry, where the entered characters are masked with asterisks, is fairly common.) In this case, the dialog should not enable the Next button until the passwords in both fields match. This ensures that user does not continue in the wizard until they have a valid password, but anyone looking over the user's shoulder cannot see the password.


Third, data that has been entered must remain persistent if the user goes back across the panels. Again, this isn't hard, so long as the data remains in memory. However, there's some logic to keep in mind here as well. Let's again look at the example of Panel 3 connecting and transmitting data to a server. If the user goes backwards from Panel 4, they should not jump immediately to a panel that re-transmits the exact same data to the server. Instead, they need to skip over the step that actually transmits the data and jump to Panel 2 where data can be re-entered.
If you're getting the impression that numbering our panels with an integer code is a bad idea, that's exactly right. It's often better to give each panel an Object identifier, such as a string. Then, when we need to move forward or backward, we can ask the current panel for the identifier of the next panel or the previous panel that it should traverse to. Note that the next and previous panel identifiers returned by the current panel are not guaranteed to remain constant, and may change based on context and user input.

So, with those design considerations in mind, let's outline a set of classes that we're going to write to create our extensible wizard dialog.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Creating Wizard Dialogs with Java Swing

View Tutorial:
Creating Wizard Dialogs with Java Swing

Related Tutorials:

Programming Java threads in the real world, Part 5 - JavaWorld - February 1999
Programming Java threads in the real world, Part 5 - JavaWorld - February 1999
 
Java Tip 72: Press Escape to close your Swing dialog windows
Java Tip 72: Press Escape to close your Swing dialog windows
 
Java 2 introduces print capability to the Swing Forum - JavaWorld June 1999
Java 2 introduces print capability to the Swing Forum - JavaWorld June 1999
 
Scripting power saves the day for your Java apps
Scripting power saves the day for your Java apps
 
Implement a J2EE-aware application console in Swing
Implement a J2EE-aware application console in Swing
 
Take control with the Proxy design pattern
Take control with the Proxy design pattern
 
Speed up your Swing GUI construction with better building blocks
Speed up your Swing GUI construction with better building blocks
 
Interesting ...
Interesting ...
 
JXMLAppKit 2.0
JXMLAppKit is a pure Swing java framework for editing an XML document with multiple XML editors.
 
YourKit Java Profiler 2.5.2 Released
YourKit Java Profiler 3.2 Released With help of YourKit Java Profiler, an outstanding tool for Java professionals, you can easily solve wide range of CPU and memory related performance problems in J2EE and J2SE applications.
 
Quaqua Look And Feel
Quaqua Look And Feel The Quaqua Look and Feel (Quaqua) is an implementation of Apple's Aqua Human Interface Guidelines in Java. Quaqua is not yet a self-contained look and feel. As Quaqua matures, it provides a steadily growing number of user elements
 
Wi.Ser (WidgetServer) unified rich client framework
Wi.Ser is a Java/XML server-side GUI-framework which enables an application to run as either a monolithic Swing application, a thin-client/server Swing application, or as a Web application without any change!
 
InfoNode (Java Components)
InfoNode Docking Windows is a pure Java Swing based docking windows framework. The best way to see features of InfoNode Docking Windows is to try the Web Start demos.
 
YourKit Java Profiler 3.2 Released
With help of YourKit Java Profiler, an outstanding tool for Java professionals, you can easily solve wide range of CPU and memory related performance problems in J2EE and J2SE applications.
 
UML 2.0 Sequence Diagramming
Modeling Complex Code in SunONE Studio with Embarcadero's Integrated Modeling Developement Environment, Describe.
 
Creating EJB clients using the Eclipse Rich Client Platform
This article shows how to build a sample EJB client using the Eclipse Rich Client Platform (RCP), which has become increasingly popularity due to its extensible nature.
 
Advanced Synth
Take an in-depth look at the Synth look and feel, the newest addition to Swing introduced in Java 5.0. Synth lets developers rapidly create and deploy custom looks for an application by introducing the concept of a "skin" to Java UI programming.
 
Sanssouci is a Java framework for autogenerating fancy Swing-GUIs via introspection.
Sanssouci is a Java framework for autogenerating fancy Swing-GUIs via introspection which display objects directly to the user
 
UltraLightClient Community Site
Community-driven Wiki site for UltraLightClient Code Snippets and Contributions If you want to contribute, please go to Register as Committer. There is no support for the content on this site by Canoo. Committers agree that the code can be used free of c
 
Creating Wizard Dialogs with Java Swing
Wizard dialogs are ubiquitous in today's desktop applications. This article creates a framework for a simple wizard dialog, complete with Back, Next, and Cancel buttons that you can extend for use in your applications as necessary.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.