Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2004

Tip: Looking for answers? Try searching our database.

JTextArea cut and paste question

Thread view: 
Andrew Walsh - 13 Jun 2004 18:59 GMT
On MS Windows, I'm using ctl-C and ctl-V to cut and paste text info
between applications.

But when I use ctl-C to copy text from a JTextArea, it loses its
line endings ("\r\n" in this case). Can anyone please give me
a clue?
Alan Moore - 14 Jun 2004 07:18 GMT
>On MS Windows, I'm using ctl-C and ctl-V to cut and paste text info
>between applications.
>
>But when I use ctl-C to copy text from a JTextArea, it loses its
>line endings ("\r\n" in this case). Can anyone please give me
>a clue?

Actually, Swing text components use "\n" to separate lines.  When you
use the built-in methods to paste text into the JTextArea or to read
text in from a file, the line separators get converted.  But no such
conversion takes place when you cut or copy from the JTextArea, so it
may that whatever you're pasting the text into just doesn't recognize
the "\n" for what it is.
Andrew Walsh - 14 Jun 2004 19:05 GMT
> Actually, Swing text components use "\n" to separate lines.  When you
> use the built-in methods to paste text into the JTextArea or to read
> text in from a file, the line separators get converted.

ahaa, thanks very much. I suppose I could write my own code to
paste the contents of the text component into clipboard using platform
specific line-endings and invoke it using a button instead of ctl-c.

Sound feasible? Or is there an obviously easier solution?
Steve W. Jackson - 14 Jun 2004 20:51 GMT
>:Alan Moore <jbigboote@yoyodyne.com> wrote in message
>:news:<qagqc0li96c875cdotukqiguptu425oiu8@4ax.com>...
[quoted text clipped - 7 lines]
>:
>:Sound feasible? Or is there an obviously easier solution?

I think you should be able to use the copy() method inherited from
JTextComponent, shouldn't you?  The API says it transfers the currently
selected range to the system clipboard.  JTextArea, JTextPane and
JEditorPane all inherit from that common abstract class.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama

Alan Moore - 15 Jun 2004 07:33 GMT
>> Actually, Swing text components use "\n" to separate lines.  When you
>> use the built-in methods to paste text into the JTextArea or to read
[quoted text clipped - 5 lines]
>
>Sound feasible? Or is there an obviously easier solution?

I think that would be the easiest way.  I once looked into the
possibility of overriding the existing behavior, but gave up after
taking over an hour just to *find* the relevant code.  Adding your own
action should be much less painful.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.