Forums Register Login
swng text field issues
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?

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.
Thanks for your answer....

What about the second question?

I've never did anything with carets (because that's how its called), so I can't help you with that.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

This thread has been viewed 679 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jan 18, 2018 11:24:08.