File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Cut/Copy/Paste from JTextField? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Cut/Copy/Paste from JTextField?" Watch "Cut/Copy/Paste from JTextField?" New topic

Cut/Copy/Paste from JTextField?

Matt Hazan

Joined: Jan 27, 2011
Posts: 29
I am fairly new to Java programming and I was wondering if someone can help me figure out how to use the JTextComponent cut(), paste(), etc... tools.

My program has text fields that appear in a JFrame... I also have an Edit menu where the user could copy, paste, and cut the text in the selected text in the textfield area.

What I tried to do is simply use myField.cut(); (which should work, i think), However, this does not work. I am not getting an error or a warning, it compiles and runs fine, however when I try to cut the text in the program it does not respond, the text remains as if I never tried to 'cut'.

Any help will be greatly appreciated!

Thanks in advance!
Darryl Burke

Joined: May 03, 2008
Posts: 5115

To get better help sooner, post an SSCCE that demonstrates the problem.

luck, db
There are no new questions, but there may be new answers.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2454
The section from the Swing tutorial on Text Component Features shows you how to implement copy/cut/paste using the Actions defined in the Editor Kit.
I agree. Here's the link:
subject: Cut/Copy/Paste from JTextField?
It's not a secret anymore!