It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea" Watch "JTextArea" New topic


Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
If I create a JTextArea, and type something, then how do I copy the text into another JTextArea?

Also, how do I save the text in the JTextArea into a text file?

amerzil co-ed student<br />"Praise be the Code"
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632

for file reading/writing
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Hi, Karabao

Welcome to JavaRanch! Please adjust your display name to meet the JavaRanch Naming Policy.
You can change it here.


"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Do you mean you want the second text area to reflect at all times what's in the original text area? You can install a javax.swing.event.DocumentListener on the first text area's document to do that. Again, you just have to copy the text value of the first into the second as Michael Dunn showed before.

James Carman, President<br />Carman Consulting, Inc.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Moving to our Swing forum...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: JTextArea
It's not a secret anymore!