• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

swng text field issues  RSS feed

 
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.
 
Sheriff
Posts: 21459
96
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: 21459
96
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!