WizardPane : Disable 'Previous' button on

2019-08-13 15:11发布

问题:

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() {}
}

回答1:

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;
            }
        }
    }
};


回答2:

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); 
         }
    });       
}


回答3:

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);

        }
    }
}