I have a JTextArea and I want to disable blinking from it. I have tried to set focusable to false, but it doesn't seem to work. I also set editable to false and it doesn't work either. Any idea?
1 Answers
Update
getCaret().setVisible()
doesn't seem to have any effect, at least with the Metal and Windows 7 L&Fs.
Here's two suggestions that might be enough for you, depending on what your final requirements:
Set the caret color to the same color as the
JTextField
background, effectively making it invisible.myJTextField.setCaretColor(myJTextField.getBackground());
If you want to show the caret at a later time (say when the field gets focus), you could switch back to the original color (the documentation says passing a
null
will do that) when yourJTextField
gets focus.Set the blink rate to 0 so even though the cursor will be visible, it won't be blinking.
myJTextField.getCaret().setBlinkRate(0);
It seems like you want to hide the caret (the |
cursor that indicates the current text insert position).
You can use JTextField.getCaret().setVisible(false);

- 20,221
- 2
- 60
- 51
-
I have tried that before, dude, but it seemed not to work. Thanks anyway – Mar 15 '11 at 12:21
-
Sorry, you didn't mention what you'd already tried. And you're right - this doesn't work! See my updated answer for a couple other suggestions. – no.good.at.coding Mar 15 '11 at 15:28
-
I will try the first later, thanks for the suggestions. I've already tried the second option and it didn't work. – Mar 15 '11 at 20:52