0

在 Charm 3.0.0 上,可以实例化Dialog一次并showAndWait多次调用。在 Charm 4.0.1 上调用 dialog.showAndWait() 两次会导致 NPE。那么我们每次想要显示的时候都必须重新初始化一个Dialog吗?

public class MyApp extends MobileApplication {

    private Dialog<ButtonType> dialog;

    @Override
    public void init() {

        addViewFactory(HOME_VIEW, () ->
        {
            initDialog();

            Button button = new Button("Show dialog");
            button.setOnAction(event -> dialog.showAndWait());

            return new View(button);
        });

    }

    private void initDialog() {
        dialog = new Dialog<>();
        dialog.setTitle(new Label("This is a regular dialog"));
        dialog.setContent(new Label("Just a regular dialog, plain and simple"));

        Button okButton = new Button("OK");
        okButton.setOnAction(e ->
        {
            dialog.hide();
        });

        dialog.getButtons().add(okButton);
    }
}    
4

0 回答 0