-
Bug
-
Resolution: Unresolved
-
P4
-
8, 17, 19, 20
-
x86
-
linux
On Ubuntu 22 run the attached text case. After code is complete click on the button in the window and then click on the text field and then stop moving the mouse. Cursor will blink couple of times and then will stop blinking. If mouse enters or leaves the text field cursor will start blinking again but again will stop after couple of times. Seems like some problem with the repaint() because as far as i can tell the repaint is being called after visibility is triggered.
-- Cut
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Robot;
import java.lang.reflect.InvocationTargetException;
public class CaretThing {
static JFrame frame;
static JTextField textField;
static Robot robot;
static JButton button;
static void printBlinkRate() {
System.err.println("Caret blink rate: " + textField.getCaret().getBlinkRate());
}
static void requestFocus(Component component) throws InterruptedException, InvocationTargetException {
robot.waitForIdle();
robot.delay(300);
SwingUtilities.invokeAndWait(() -> {
System.err.println("Requesting focus on " + component);
printBlinkRate();
component.requestFocus();
printBlinkRate();
});
}
static void changeEditable() throws InterruptedException, InvocationTargetException {
robot.waitForIdle();
robot.delay(300);
SwingUtilities.invokeAndWait(()-> {
System.err.println("Changing editable");
printBlinkRate();
textField.setEditable(!textField.isEditable());
printBlinkRate();
});
}
public static void main(String[] args) throws Exception {
robot = new Robot();
robot.setAutoWaitForIdle(true);
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("Hey");
frame.setLocationRelativeTo(null);
textField = new JTextField("Some long field value");
textField.setEditable(false);
frame.setLayout(new BorderLayout());
frame.add(textField, BorderLayout.NORTH);
button = new JButton("Button");
button.addActionListener((e)-> printBlinkRate());
frame.add(button, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
button.requestFocus();
textField.getCaret().setBlinkRate(250);
});
requestFocus(textField);
requestFocus(button); // comment this to get 0 blink rate on editable field
changeEditable();
requestFocus(textField);
SwingUtilities.invokeAndWait(CaretThing::printBlinkRate);
}
}
-- Cut
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Robot;
import java.lang.reflect.InvocationTargetException;
public class CaretThing {
static JFrame frame;
static JTextField textField;
static Robot robot;
static JButton button;
static void printBlinkRate() {
System.err.println("Caret blink rate: " + textField.getCaret().getBlinkRate());
}
static void requestFocus(Component component) throws InterruptedException, InvocationTargetException {
robot.waitForIdle();
robot.delay(300);
SwingUtilities.invokeAndWait(() -> {
System.err.println("Requesting focus on " + component);
printBlinkRate();
component.requestFocus();
printBlinkRate();
});
}
static void changeEditable() throws InterruptedException, InvocationTargetException {
robot.waitForIdle();
robot.delay(300);
SwingUtilities.invokeAndWait(()-> {
System.err.println("Changing editable");
printBlinkRate();
textField.setEditable(!textField.isEditable());
printBlinkRate();
});
}
public static void main(String[] args) throws Exception {
robot = new Robot();
robot.setAutoWaitForIdle(true);
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame("Hey");
frame.setLocationRelativeTo(null);
textField = new JTextField("Some long field value");
textField.setEditable(false);
frame.setLayout(new BorderLayout());
frame.add(textField, BorderLayout.NORTH);
button = new JButton("Button");
button.addActionListener((e)-> printBlinkRate());
frame.add(button, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
button.requestFocus();
textField.getCaret().setBlinkRate(250);
});
requestFocus(textField);
requestFocus(button); // comment this to get 0 blink rate on editable field
changeEditable();
requestFocus(textField);
SwingUtilities.invokeAndWait(CaretThing::printBlinkRate);
}
}
- duplicates
-
JDK-8299050 [Linux] Caret blinks several times and stops
- Closed
- relates to
-
JDK-8074248 Repaint don't works correctly
- Open
- links to
-
Review openjdk/jdk/12939