RFR: 8319880: JTextField text selection doesn't stop if ended during loss of window focus [v3]
Prasanta Sadhukhan
psadhukhan at openjdk.org
Thu Dec 4 05:23:59 UTC 2025
On Wed, 3 Dec 2025 10:56:24 GMT, Anass Baya <abaya at openjdk.org> wrote:
>> **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
>
> Anass Baya has updated the pull request incrementally with one additional commit since the last revision:
>
> The issue occurs only on Wnidows
src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java line 551:
> 549: if (SwingUtilities.isLeftMouseButton(e)) {
> 550: lastClickMillis = e.getWhen();
> 551: dragActive = true;
should we set `dragActive ` here? it's just mousePressed, in which case all mousePress event will have dragActive set.
I guess it should be set in `mouseDragged` and reset in `mouseReleased`, no?
test/jdk/javax/swing/JTextField/TextSelectionFocusLoss/TextSelectionFocusLoss.java line 38:
> 36: * @test
> 37: * @key headful
> 38: * @requires (os.family == "windows")
even if it happens only on windows, since this is automated test, no point restricting for other platforms where it should pass automatically...atleast it will catch any regression in future if it happens otherwise later..
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28582#discussion_r2587602822
PR Review Comment: https://git.openjdk.org/jdk/pull/28582#discussion_r2587602126
More information about the client-libs-dev
mailing list