Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

copy , paste functionality for JTextArea

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have an editor using JTextArea. I want to add cut , copy , paste options on right click.
How can I go about it. any help will be appreciated.

Thanks

Gaurav
 
Author
Posts: 974
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kay jee:
I have an editor using JTextArea. I want to add cut , copy , paste options on right click.
How can I go about it.



JTextArea (and all JTextComponents) support cut/copy/paste via the keyboard (ctrl-x, ctrl-c, ctrl-v on most LnFs) by default.

They also have simple cut(), copy(), and paste() methods. If you want a right-click popup menu, you can create menu items to call those three methods and put them in a JPopupMenu. There is some JPopupMenu information in the java tutorial.
 
kay jee
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi brian

Thanks a lot. I was actually looking for the pop up menu thing. thanks for helping.

But how can i provide a search/find option in my JTextArea. Is there any built in java lib or is there any easily available third party tools.

I will appreciate any help.

Thanks

kg
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
probably is 3rd party tools, but it wouldn't be too hard to roll-your-own.

textArea.getText() is just a String, depending on search options 'Match Case'
'Whole Word' etc - String.indexOf(..), regex, etc
 
kay jee
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah me thinks so too.
Thanks for all the help.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Cole wrote:

Originally posted by kay jee:
JTextArea (and all JTextComponents) support cut/copy/paste via the keyboard (ctrl-x, ctrl-c, ctrl-v on most LnFs) by default.



For some bizarre reason Ctrl-C and Ctrl-V only work when I run a Swing app standalone under Windows 7. When I run it as an Applet, in any browser, they do nothing. How do I get them to work in a browser? Signed or unsigned does not seem to help. Do I have to revert to AWT TextField and TextArea for browser use?

 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic