This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
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 The Software Craftsman this week in the Agile 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: 4825

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: 2282
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?