I have this code snippet:
Alert alert = new Alert(AlertType.WARNING, "The format for dates is year.month.day. " + "For example, today is " + todayToString() + ".", ButtonType.OK, ButtonType.CANCEL); alert.setTitle("Date format warning"); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK) { formatGotIt = true; }
Above, I request two buttons titled "Yes" and "No." However, I wish to change them both.
You can define your own button types. In this example the buttons' text is foo
and bar
:
ButtonType foo = new ButtonType("foo", ButtonBar.ButtonData.OK_DONE); ButtonType bar = new ButtonType("bar", ButtonBar.ButtonData.CANCEL_CLOSE); Alert alert = new Alert(AlertType.WARNING, "The format for dates is year.month.day. " + "For example, today is " + todayToString() + ".", foo, bar); alert.setTitle("Date format warning"); Optional<ButtonType> result = alert.showAndWait(); if (result.orElse(bar) == foo) { formatGotIt = true; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With