2

How can I disable the 'Previous' button on my Screen of the ControlsFX WizardPane? I am trying it with this method prev.setDisable(true) but what I have is NullPointerException.

public class MainApp extends Application {
    Wizard wizard = new Wizard();

    WizardPane1 page1 = new WizardPane1();

    WizardPane page2 = new WizardPane();

    WizardPane page3 = new WizardPane() {
        @Override
        public void onEnteringPage(Wizard wizard) {
            Node prev = lookupButton(ButtonType.PREVIOUS);
            prev.setDisable(true);
        }
    };

    page1.setContent(page1.getInit());

    wizard.setFlow(new LinearFlow(page1, page2, page3));
    wizard.showAndWait();

}

public class WizardPane1 extends WizardPane {
      public void initWizard() {}
}
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
Z.B
  • 61
  • 8
  • What is Wizard class? – Uluk Biy Aug 26 '15 at 08:03
  • Hi you can look from this page http://controlsfx.bitbucket.org/org/controlsfx/dialog/Wizard.html – Z.B Aug 26 '15 at 08:05
  • What does it print for s.o.println(getButtonTypes()); in onEnteringPage() method? – Uluk Biy Aug 26 '15 at 08:30
  • Output : [ButtonType [text=Vorheriger, buttonData=BACK_PREVIOUS], ButtonType [text=Nächster, buttonData=NEXT_FORWARD], ButtonType [text=Fertigstellen , buttonData=FINISH], ButtonType [text=Abbrechen, buttonData=CANCEL_CLOSE]] – Z.B Aug 26 '15 at 08:47
  • My texts are in German (text=....) – Z.B Aug 26 '15 at 08:51

3 Answers3

1

This will disable the button.

@Override 
public void onEnteringPage( Wizard wizard ) { 
     for ( ButtonType type : getButtonTypes() ) {
         if ( type.getButtonData().equals(ButtonBar.ButtonData.BACK_PREVIOUS) ){
             System.out.println("Found Back button");
             previous_button = (Button) lookupButton( type );
             break;
         }
     }

     Platform.runLater(new Runnable() {
         @Override 
         public void run() {        
          previous_button.setDisable(true); 
         }
    });       
}
Jason Pratt
  • 121
  • 4
0

I didn't try but according to source code of Wizard, it adds its own "Previous" button, and to lookup it you may need to get the reference exactly to the same ButtonType by first looking it up using the ButtonData:

WizardPane page3 = new WizardPane()
{
    @Override
    public void onEnteringPage( Wizard wizard )
    {
        for ( ButtonType type : getButtonTypes() )
        {
            if ( type.getButtonData().equals(ButtonBar.ButtonData.BACK_PREVIOUS) )
            {
                Node prev = lookupButton( type );
                prev.setDisable( true );
                break;
            }
        }
    }
};
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
-1

This is the solution and it works :))

@Override
public void onEnteringPage(Wizard wizard) {

    ObservableList<ButtonType> list = getButtonTypes();

    for (ButtonType type : list) {
        if (type.getButtonData().equals(ButtonBar.ButtonData.BACK_PREVIOUS)) {
            Node prev = lookupButton(type);
            prev.visibleProperty().setValue(Boolean.FALSE);

        }
    }
} 
Z.B
  • 61
  • 8
  • You are hiding the button, not disabling it as asked in your question. Beside that it has no difference from the other answer. – Uluk Biy Aug 26 '15 at 12:52
  • You are right. I have a solution for hidding but not for disabling. – Z.B Aug 26 '15 at 12:58