RFR: 8319880: JTextField text selection doesn't stop if ended during loss of window focus
Anass Baya
abaya at openjdk.org
Mon Dec 1 16:33:07 UTC 2025
**Analysis :**
The issue is that on Win32, if the window is not active, we dont receive mouse events because we release the capture
So the problem is the following:
We start selecting text from the right to the extreme left.
Then we switch to another window( the window lose focus ), and we release the mouse
But when we return to the window, the caret drag is still active and does not stop. as the window did not recieved the mouse release event
**Proposed fix:**
In the Caret class, we added a logic to ignore the drag if the focus was lost due to window switching unless a new mouse press happens
**Test:**
TextSelectionFocusLoss:
- OK with the fix on all platforms.
- NOK without the fix on Windows.
In the test, I was going to add a dummy frame in a separate process to ensure there was another app to switch to. However, this seems unnecessary, as we always have an additional app; at least the one responsible for starting the test.
-------------
Commit messages:
- Add Test
- Add fix
Changes: https://git.openjdk.org/jdk/pull/28582/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28582&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8319880
Stats: 147 lines in 3 files changed: 146 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/28582.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28582/head:pull/28582
PR: https://git.openjdk.org/jdk/pull/28582
More information about the client-libs-dev
mailing list