Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide the insert caret in a JTextField?

I'm making a calculator program with Java using Java's Swing toolkit, and I want it to be similar to Windows' (default) calculator.

I have a JTextField for entering the numbers. You can see the cursor being displayed. I want to hide it.

enter image description here

I tried doing this:

textField.getCaret().setVisible(false);

but it didn't help. I also tried invoking it before and after I created and initialized the window but it still didn't work. The cursor was there.

I looked up the JTextField and Caret documentation but didn't find anything that could be useful for me, other than the setVisible() method which didn't work.

How can I hide the insert caret/cursor?

like image 596
Marko Kitonjics Avatar asked Sep 01 '25 05:09

Marko Kitonjics


1 Answers

you could just make it invisible, you can try

textField.setCaretColor(Color.WHITE);
like image 53
Tsakiroglou Fotis Avatar answered Sep 02 '25 17:09

Tsakiroglou Fotis