Re: JTextField - how to disable selecting text in this component?




dako wrote:
Brandon McCombs napisal(a):

setEnabled(false) and setEditable(false) are different and
setEditable(false) would be what you want to prevent people from putting
text in it. Disabling the component is done by setEnabled() which wasn't
what Mearvk proposed to you.

Sorry. I forget say I don't want to prevent component from puting text
in it but only whilst selecting text in it. Is it imposible?

Try subclassing JTextField. When the mouseDrag event fires inside the
JTextField do something like return immediately or set the focus on the
parent JComponent. You will want to catch keyboard input also. (Block
things like ctrl+A, ctrl+C, shift+end and shift+home)

I think it can be done but it will require some hacking and time. There
may be a better way but this is what I can figure.

Good luck,

Mearvk

.