On Mon, 5 Apr 2021 22:58:47 GMT, Kevin Rushforth <k...@openjdk.org> wrote:
>> When DialogPane#getButtonTypes().setAll() is called twice with the same >> argument(s), DialogPane#lookupButton does not return the node which is shown >> inside the button bar. >> This is due DialogPane adding two list change listeners to 'buttons' >> (#getButtonTypes). They have the wrong order, which will result in the >> button bar not changing at all and the 'buttonNodes' list will recreate the >> dialog button(s). >> Finally, this will make DialogPane#lookupButton returning the 'wrong' >> button, which is in fact not used inside the dialog button bar. > > modules/javafx.controls/src/main/java/javafx/scene/control/DialogPane.java > line 1062: > >> 1060: boolean hasDefault = false; >> 1061: for (ButtonType cmd : getButtonTypes()) { >> 1062: Node button = buttonNodes.get(cmd); > > Why was this change needed? This change is not needed for the fix. I removed it, because #computeIfAbsent() isn't needed anymore. The (now) first listener will run and create/remove buttons based off the changes to #getButtonTypes(). The second listener (which is calling this method) will use all created buttons (to put them inside the ButtonBar). -> So only a simple #get() is needed. #computeIfAbsent() basically masked this bug before, as it was also creating a button, if missing. But as mentionend, when we are here, all buttons should be already created by the first listener. ------------- PR: https://git.openjdk.java.net/jfx/pull/432