RFR: 6741930: JOptionPane doesn't honour Focus Traversal Policy
Sergey Bylokhov
serb at openjdk.org
Mon Feb 16 23:57:10 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..
This seems to contradict the spec of BasicOptionPaneUI#initialFocusComponent and the spec of the BasicOptionPaneUI#selectInitialValue() itself?
/** Component to receive focus when messaged with selectInitialValue. */
protected Component initialFocusComponent;
/**
* If inputComponent is non-null, the focus is requested on that,
* otherwise request focus on the default value
*/
public void selectInitialValue(JOptionPane op) {
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29738#issuecomment-3911037641
More information about the client-libs-dev
mailing list