Geertjan's Blog

  • October 4, 2005

How Wizards Work (Part 4): Your Own Iterator

Geertjan Wielenga
Product Manager
When you use the Wizard wizard to create files for a dynamic wizard—because you want the user to be able to skip steps or to branch off to a subset of the wizard steps—one of the files created for you subclasses WizardDescriptor.InstantiatingIterator. This is the class that you use to define what the next step in the wizard will be, depending on the choices made by the user in the current and/or previous step. But a subclass of WizardDescriptor.InstantiatingIterator is also created for you when you make this selection in the Wizard wizard:

In this case, the wizard is invoked—not by an action, as in the case of custom wizards—but by the New File wizard. When you select it in the New File wizard, the wizard is invoked. So, in this case, since you have no action, where do you put the code that specifies what happens at the end of the wizard? In How Wizards Work (Part 3): Your First Wizard, the peformAction method contained this code:

if (!cancelled) {
StringBuffer message = new StringBuffer();
Integer destLocation = (Integer)
message.append("You're going to: " +
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message.toString()));

But, now that we don't have an action, and therefore no performAction either, we fill out the iterator's instantiate() method (part of the default code generated by the Wizard wizard) instead:

public Set instantiate() throws IOException {
boolean cancelled = wizard.getValue() != wizard.FINISH_OPTION;
if (!cancelled) {
StringBuffer message = new StringBuffer();
Integer question = (Integer) wizard.getProperty(NewWizardVisualPanel1.QUIZ_QUESTION);
message.append("Your question: " + NewWizardVisualPanel1.getAsString(question.intValue()));
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message.toString()));
return Collections.EMPTY_SET;

For the rest, the one-panel wizard works exactly as in How Wizards Work (Part 3): Your First Wizard. Here's what my new one-panel New File wizard looks like:

Update: There are more parts to this series... Part 1, Part 2, Part 3, and Part 5.

Join the discussion

Comments ( 12 )
  • Gustavo Tuesday, October 11, 2005
    Hi Geertjan.
    I'd like to know if things like the button labels and the string "Steps" on the left can be changed/localized, programatically at least.
    Great weblog!
  • Geertjan Monday, October 17, 2005
    Hi Gustavo, that's a great question. I completely agree with you that those strings should be localizable. As far as I can see (and also after talking to a developer in the web area) this is currently not possible. I've created an issue for this here. Please add a comment to the issue to indicate that you find it important.
  • Gustavo Monday, October 17, 2005
    While I was waiting for your response, I found that the strings are retrived from Bundle.properties in org-openide-dialogs.jar. I'm new to NetBeans module development and in fact new to NetBeans IDE too. BTW, a developer marked the issue RESOLVED (although it seems there are no such files for Spanish, sad for me...)
    Thank you very much again.
  • Geertjan Monday, October 17, 2005
    Instead of using my blog to talk about your concerns, please use the issue instead. Just go to the issue and add your comments. If you want to reopen it, reopen it.
  • Gustavo Wednesday, October 19, 2005
    Geertjan, I really don't understand you. First you say \*great question\*, and later you ask me not to talk on your blog... Like I said, I'm new to NetBeans, didn't know I could reopen an issue. Sorry, it won't happen again.
  • Geertjan Wednesday, October 19, 2005
    :-) Well, it is a great question. My only point is that if you want to comment on an issue in Issuezilla, it's probably best to do so within the issue in Issuezilla, rather than within my blog. :-)
  • Gustavo Wednesday, October 19, 2005
    Since that issue came out from this very talk and it wasn't \*a issue in Issuezilla\* before, I thought you probably wanted to know. Anyway, I hope not all NetBeans bloggers (with comments enabled) will take NetBeans newcomers posts like this!
    Not a great weblog anymore... :-(
  • Geertjan Wednesday, October 19, 2005
    Look, Gustavo, my only point was that if you have something to say about an issue, it's best to say it in the issue itself, so that your comments can be tracked and so that, as in this case, the developer who closed your issue can also see your comments. You really are free to say whatever you want in this blog, and I really welcome anything you have to say.
  • Pierre Wednesday, March 21, 2007
    Hello Geertjan,
    I'm a french student and I work on a GIS Software. I want to make a dynamic wizard. I create it but I can't get it an instance like a static one. I can't instance the iterator in the layer.xml. How can i do that ?
    PS : Excuse me for my English ;)
  • Geertjan Wednesday, March 21, 2007
    Hi Pierre. There's no need for your English to be excused, because it is great! I'm not sure how to answer your question. The best thing to do is to join the dev@openide.netbeans.org mailing list, if you haven't already, and ask your question there. All the experts, including the people who created the NetBeans Platform, are on that mailing list.
  • Jo Vark Monday, December 7, 2009

    Hi! Very useful post. I wonder if you could tell me how to hide the "Help" button.


  • guest Monday, September 1, 2014

    Hello Geertjan,

    I got problems with using the valid-function during runtime.

    My return-value is:


    public boolean isValid() {

    return valid;

    I am using a JTree and if a node is selected the "Next"-Button should be enabled and if a node is not selected the "Next"-Button should be disabled again.

    So valid has to be true or false.

    So far so good....

    Via .setValid(true) or .setValid(false) in my VisualPanel-Class (using TreeSelectionListener and valueChanged-Event) I can pass the correct value but nothing happens...

    What do I have to consider using the valid-Function during runtime? (I cannot use readSettings - or storeSettings because they catch the event to the wrong time - not runtime).

    Thanks a lot

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.