RFR: 6741930: JOptionPane doesn't honour Focus Traversal Policy
Prasanta Sadhukhan
psadhukhan at openjdk.org
Tue Feb 24 04:42:49 UTC 2026
On Mon, 16 Feb 2026 10:43:50 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
> The FocusTraversalPolicy of a JOptionPane (JDialog) "reports" via `FocusTraversalPolicy.getInitialComponent`/`FocusTraversalPolicy.getFirstComponnent` that the focusable component passed to a JOptionPane, should get the initial focus. This however doesn't always happen, as the text field's FocusListener methods focusGained and focusLost are not invoked.
> Fix is made to honor the first focusable component of custom component (if present) and set the focus accordingly..
> This will cause the component's focusGained/focusLost method to get called.
> CI testing is ok..
So, how can we decide? we can either close this as "Wont Fix" or fix as per this PR as it is not causing any regression
> > So, how can we decide? we can either close this as "Wont Fix" or fix as per this PR as it is not causing any regression
>
> You could also do some research into how this API is actually used. Since you already started changing that method, I assume you have an idea why the method parameter should be used instead of the fields, as suggested by this PR.
It is only called from one place
https://github.com/openjdk/jdk/blob/cb3a57ccede6709205e75c7eb2ff9998cb7a82d0/src/java.desktop/share/classes/javax/swing/JOptionPane.java#L2300-L2303
and as per OptionPaneUI spec it should request the component to have focus which I believe the author of this method intended for the passed component else there is no need to pass in the param
https://github.com/openjdk/jdk/blob/cb3a57ccede6709205e75c7eb2ff9998cb7a82d0/src/java.desktop/share/classes/javax/swing/plaf/OptionPaneUI.java#L44-L49
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29738#issuecomment-3948951430
More information about the client-libs-dev
mailing list