The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

program a button that copy whatever in a JTextArea

Say there are a JButton called copy, and a JTextArea called txtArea, once the button clicked a copy of whatever in the JTextArea is, moved to the clipboard so that I can paste it to any text editor (e.g. notepad)

Re: program a button that copy whatever in a JTextArea

Read the API for the JTextComponent (Java 2 Platform SE 5.0)
It only works for the selected text. A workaround is to save the selection, select all, call copy, then reset the original selection. I haven't implemented something like that in a while but it should work. The alternative is to make calls directly to the Clipboard. You can find many solutions to this by googling "java Clipboard copy paste"