-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8, 11, 17, 21, 22, 23
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
MacOS Sonoma 14. Also reproduced on Monterrey.
Java21. Also reproduced on many older java versions.
Standard LAF. Could not reproduce in Windows/Linux.
A DESCRIPTION OF THE PROBLEM :
Swing. Using standard JTextField. No listeners.
When you select text using mouse, from right to left, to select text (selection must include the first character in the field).
75% of the time, the selection / highlighter gets 'stuck'. When this occurs, then all typing overwrites what's already in the field (occupying the selection area)..
I suspect the AquaCaret class.... Perhaps the mouse is being dragged flag is not being released?
Seems similar to JDK-8319880 - but also different. Hence a new report.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code... Very simple. Create a JFrame, add a JPanel, add a JTextField, and popup the form...
Select text using mouse, carefully drag from right to left, must include first character.
Start typing very fast.
If condition does not appear, then try selection again... It occurs very often.
For example. If 'hello' was in the field, and then you select 'hello' click and drag mouse from right end of text starting after the 'o' left to include the 'h', so entire field is highlighted. Then type fast, everything you type (either one or two characters) will appear in the field and re highlight itself.. Keep typing and you just keep replacing the same highlighted characters...
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After you select text (right to left) and type, then selection/highlighter should remove itself and typing should not keep overwriting itself. i.e. typed text should insert into the field.
ACTUAL -
As described... Typed text should insert into the field and selection should remain highlighted.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
public class Main {
public static void main(String[] argv) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
// Own class only so we can use a debugger with breakpoint....
class JFR extends JFrame {
public JFR(String title) {
super(title);
}
public final void processEvent(AWTEvent evt) {
int id = evt.getID();
super.processEvent(evt);
}
}
JFrame f = new JFR("TextFieldBug");
JPanel p = new JPanel();
JTextField tf1 = new JTextField("TF11111111");
p.add(tf1);
f.add(p);
f.pack();
f.setSize(new Dimension(400, 60));
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
FREQUENCY : often
MacOS Sonoma 14. Also reproduced on Monterrey.
Java21. Also reproduced on many older java versions.
Standard LAF. Could not reproduce in Windows/Linux.
A DESCRIPTION OF THE PROBLEM :
Swing. Using standard JTextField. No listeners.
When you select text using mouse, from right to left, to select text (selection must include the first character in the field).
75% of the time, the selection / highlighter gets 'stuck'. When this occurs, then all typing overwrites what's already in the field (occupying the selection area)..
I suspect the AquaCaret class.... Perhaps the mouse is being dragged flag is not being released?
Seems similar to JDK-8319880 - but also different. Hence a new report.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code... Very simple. Create a JFrame, add a JPanel, add a JTextField, and popup the form...
Select text using mouse, carefully drag from right to left, must include first character.
Start typing very fast.
If condition does not appear, then try selection again... It occurs very often.
For example. If 'hello' was in the field, and then you select 'hello' click and drag mouse from right end of text starting after the 'o' left to include the 'h', so entire field is highlighted. Then type fast, everything you type (either one or two characters) will appear in the field and re highlight itself.. Keep typing and you just keep replacing the same highlighted characters...
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After you select text (right to left) and type, then selection/highlighter should remove itself and typing should not keep overwriting itself. i.e. typed text should insert into the field.
ACTUAL -
As described... Typed text should insert into the field and selection should remain highlighted.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
public class Main {
public static void main(String[] argv) throws InterruptedException, InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
// Own class only so we can use a debugger with breakpoint....
class JFR extends JFrame {
public JFR(String title) {
super(title);
}
public final void processEvent(AWTEvent evt) {
int id = evt.getID();
super.processEvent(evt);
}
}
JFrame f = new JFR("TextFieldBug");
JPanel p = new JPanel();
JTextField tf1 = new JTextField("TF11111111");
p.add(tf1);
f.add(p);
f.pack();
f.setSize(new Dimension(400, 60));
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None found.
FREQUENCY : often
- duplicates
-
JDK-8319880 JTextField text selection doesn't stop if ended during loss of window focus
- Open
- relates to
-
JDK-8319880 JTextField text selection doesn't stop if ended during loss of window focus
- Open