WizardPane : Disable 'Previous' button on a screen

故事扮演 提交于 2020-01-02 09:58:52

问题


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:


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



回答2:


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



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

        }
    }
} 


来源:https://stackoverflow.com/questions/32221010/wizardpane-disable-previous-button-on-a-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!