如何将Netbeans向导模块添加到自己的项目?

时间:2013-07-24 19:58:34

标签: java swing netbeans wizard

我的问题是simillar to topic:
How to use netbeans module in my own project?
但我有调用创建的向导的问题。 我已将向导源和库复制到我自己的项目中。
现在我想在我的应用程序中点击一个按钮后调用一个向导(下面的按钮操作代码执行方法 - 它由Netbeans生成):

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DemoWizardAction d = new DemoWizardAction(); d.actionPerformed(evt); }


所以现在,在按钮的单击向导的框架被调用之后,但当我点击“下一步”按钮时它会消失(它应该转到第二个向导的框架)。
有人可以帮助如何正确调用向导吗?

1 个答案:

答案 0 :(得分:0)

我还说明了我的巫师消失的问题。之所以发生这种情况,是因为Trivial DialogDisplayer实现后,只要点击一个按钮就会关闭对话框。

我的解决方案:不要使用notify()方法。

我的代码示例:

public void actionPerformed(final ActionEvent e) {
  final List<WizardDescriptor.Panel<WizardDescriptor>> panels = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>();
  panels.add(new WizardPanel());
  panels.add(new WizardPanel2());
  final String[] steps = new String[panels.size()];
  for (int i = 0; i < panels.size(); i++) {
    final Component c = panels.get(i).getComponent();
    // Default step name to component name of panel.
    steps[i] = c.getName();
    if (c instanceof JComponent) { // assume Swing components
      final JComponent jc = (JComponent) c;
      jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
      jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
      jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
      jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, true);
      jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
      // jc.putClientProperty(WizardDescriptor.PROP_IMAGE,
      // ImageUtilities.loadImage("com/skytron/pvgw/icons/logo40.png", true));
      // jc.putClientProperty(WizardDescriptor.PROP_IMAGE_ALIGNMENT, "South");
    }
  }

  final WizardDescriptor wiz = new WizardDescriptor(
      new WizardDescriptor.ArrayIterator<WizardDescriptor>(panels));
  // {0} will be replaced by WizardDesriptor.Panel.getComponent().getName()
  wiz.setTitleFormat(new MessageFormat("{0}"));
  wiz.setTitle("...dialog title...");

  // this does not work outside of netbeans!!!
  // if (DialogDisplayer.getDefault().notify(wiz) ==
  // WizardDescriptor.FINISH_OPTION) {
  // do something
  // }

  // create a dialog and set it visible.
  final Dialog wizardDialog = DialogDisplayer.getDefault().createDialog(wiz);
  wizardDialog.setVisible(true);
}