how to hide and show cursor in JTextField?

R

Roy

Hi,

Is there any way to hide the cursor in the JTextField and show the
cursor when I click this field? It'd be great if I click other area
or components in the panel, hide the cursor in the JTextField again.

Thanks a lot.
Roy
 
M

Mark Space

Roy said:
Hi,

Is there any way to hide the cursor in the JTextField and show the
cursor when I click this field? It'd be great if I click other area
or components in the panel, hide the cursor in the JTextField again.

Thanks a lot.
Roy

Which cursor? Mouse? Insert caret?
 
A

Andrew Thompson

Roy wrote:
...
It is the insert caret.

Your comments do not make much sense to me.

There is an applet here that will pop a dialog with a
JTextField and JTextArea (click the 'Input' button).
<http://www.physci.org/test/resize/>

The 'insert caret' (as I understand it) will only show in
the text field/area that currently has focus, in either the
Metal or System (Win) PLAFs.

To hide the insert caret even when it is in a particular
text widget, just set the widget uneditable or disabled
(see dropdown on main applet GUI).
 
R

Roy

Roy wrote:

..


Your comments do not make much sense to me.

There is an applet here that will pop a dialog with a
JTextField and JTextArea (click the 'Input' button).
<http://www.physci.org/test/resize/>

The 'insert caret' (as I understand it) will only show in
the text field/area that currently has focus, in either the
Metal or System (Win) PLAFs.

To hide the insert caret even when it is in a particular
text widget, just set the widget uneditable or disabled
(see dropdown on main applet GUI).

Thanks a lot. I happened to setFocusable(false) for all other
components. So the JTextField is the only component that always has
focus. That is why the insert caret is always blinking.

Anway, I was told by a friend that a simple way to hide the caret in
this situation is to do the following:

MyTextField.getCaret().setVisible(false);

Thanks again.
Roy
 
M

Mark Space

Roy said:
MyTextField.getCaret().setVisible(false);

I was going to suggest the same thing Andrew did. I didn't know about
this method, good find, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top