• Post Reply Bookmark Topic Watch Topic
  • New Topic

swng text field issues  RSS feed

 
shlomy bentulilah
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have two questions regarding text field in java :

1. How can I implement/add the "undo" feature (using CTRL+Z) to a text field ?
2. In case that I clicked the text field in order to edit it / or insert a value I want the text field to loose focus when I am clicking other area of the gui.( it seems that the cursor is still in the text field....)
How can I implement it?

Thanks.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Each Swing text component has a Document. This has methods to add an UndoableEditListener. When you change the contents of the Document, either by calling methods on the Document, calling methods on the text component or simply typing in the latter, it automatically fires an undoableEditHappened event. You can catch that and add it to an UndoManager:

You can then undo as follows:

Now all you need is a key listener that calls this code when CTRL+Z is typed. And while you're at it, also add redo possibilities with CTRL+Y. The methods are basically called the same.
 
shlomy bentulilah
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answer....

What about the second question?


Thanks.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never did anything with carets (because that's how its called), so I can't help you with that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!