Solved: I figured that it isn't a bug of JavaFX, it is made like that on purpose, so you can request the result multiple times from the dialog if you don't wanna save it into a variable. To flush the cache i used setResult(null) on the dialog. That did the job for me :)
I've created a Dialog to edit/create a Person using JavaFX. But i guess i found a bug. I've added two ButtonType-objects to my dialog. One for saving and one for aborting the actions. When i use those buttons it works just fine. But if i press the 'X' to close the dialog-window, the dialog automaticly returns the last result again. That means if i aborted my last action and in my current one i press 'X' to close the window, the dialog returns no result since the abort-button didn't have one last time. But if i pressed the save-button on my last action and i press 'X' in my current one it returns the same person again, since save-button had this person in its result last time. How can i make the dialog changing to no result on closing?
Here is the action i've created:
this.createPersonAction = new Callback<ButtonType, PersonSession>() {
@Override
public PersonSession call(final ButtonType param) {
if (param.equals(PersonDialogController.this.saveButton)) {
final String firstName = PersonDialogController.this.firstNameField.getText();
final String lastName = PersonDialogController.this.lastNameField.getText();
final Person p = BeanFactory.createPerson(firstName, lastName);
if (p != null) {
return new PersonSession(p);
}
}
return null;
}
};
And here you have my two ButtonType-Objects:
private final ButtonType saveButton = new ButtonType(GuiStringRresource.LABEL_SAVE_BUTTON, ButtonData.OK_DONE);
private final ButtonType abortButton = new ButtonType(GuiStringRresource.LABEL_ABORT_BUTTON,
ButtonData.CANCEL_CLOSE);
使用Dialog.setOnCloseRequest
方法来处理这种情况。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.