Disable drag and drop for any text
Hi people, I'm here with another problem I've just realised ...
I programmed my textfield in order to accept only numbers. It does work great, but if I drag some text from any part and drop it into the textfield,
it accepts it...I was searching on the net and found some helpful information, but just about restricting a textfield to drag something of itself.
I just want to disable dropping any text into the textfield. Hope you understand and could help me...
Thanks in advance...
Re: Disable drag and drop for any text
Quote:
Originally Posted by
fauzeddd-
Hi people, I'm here with another problem I've just realised ...
I programmed my textfield in order to accept only numbers. It does work great, but if I drag some text from any part and drop it into the textfield,
it accepts it...I was searching on the net and found some helpful information, but just about restricting a textfield to drag something of itself.
I just want to disable dropping any text into the textfield. Hope you understand and could help me...
You may be trying to fix the wrong thing. My question is how did you prevent the textfield from accepting non-numeric input? Did you use a KeyListener? If so and if this is a Swing application, then that's not the way to solve it. Better is to use either a JFormattedTextField or a DocumentFilter.
Then your field can handle drag and drop or copy and paste, and keypresses.