Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy and paste a value from a text field  RSS feed

 
Smriti Anchu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a text field in a swing applicaiton. It is placed in a panel. The field is a phone number field which already has a format like
( )_ _ _- _ _ _ _
eg. (123)456-7890. When i cut this number and place it in the same text field, i am getting the full number i am getting something like
(_12)_45-_789.

But If you override the number, by selecting the whole number and pasting the cut number, then u would be getting the full number otherwise i am getting a number like this.

can anyone help me in this as early as possible. As it is very urgent hv to complete by 2 hours

thanks
smriti
 
Smriti Anchu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Did anybody get a solution to this quesiton. I have to finish this task by any means. So please, help me in this

regards
smriti
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Smriti,

Are you cutting and pasting programatically, or manually using your mouse?

Maybe you could post the code you used to setup your textfield?

Ed
 
Smriti Anchu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Eddie,

I am manually cutting and pasting the data in textfield, the data gets pasted but not in the format.

Actually we have used a 3rd party text field, where in the textfield is masked to the format ( eg. (123)123 1233).

Now how do we go about cutting and pasting the field. Since it is masked, once we cut and paste its displaying in someother format.

Or else, can u tell me, once the data is cut and before it is pasted how do we make the cursor point to the first position (i.e., before the '(' position,) If the cursor is pointed to that position, the problem is almost solved. Now once the data is cut, the cursor is pointing to the position after '(' so as such, once it is pasted, the values are moved towards right

if you have a solution to this do tell me
thanks
bye
smriti
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Smriti,

We don't really know how this third party widget works. Unless you have some documentation on its behaviour or a listing of it, by the time time you work it out and get it all to work you might as well write your own.

One simple thing you can do is to paste the contents of the cell to another textfield (one without any mods), or even just to notepad, so you can see what is coming out of this cell on a copy. Similarly, you could write a number in a textfield, or notepad, and paste that into this control so you get some idea on what it does.

Another way is to implement the DocumentListener class on a standard textfield, but that would take some work.

You could also check out "setCaretPosition(int position)" method in the JTextComponent class.

Hope that helps

Ed
 
Smriti Anchu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

Thanks a lot for your reply.. I got solution to the problem. In the keyReleased event we need to set the cursor position to present position - 1.



The topic can be closed.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!