Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy/Paste in JTextPane  RSS feed

 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,
I am currently developing a multi-window RTF Text Editor in Java using JTextPane Components.
When I use the .copy() method of the JTextPane class and I examine the content of the clipboard it only containing text (without style).
Could anyone help ?
Thanks
 
Steffen Foldager
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicolas
You might want to look into the java.awt.datatransfer package. You'll need something along the lines of a Transferable with an RTF DataFlavor.
Steffen
 
Nicolas Brasseur
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I tried to investigate DataFlavor, etc ...
In this way I wrote the following code to obtain a piece of RTF document to create a Transferable Object ...
ByteArrayOutputStream out = new ByteArrayOutputStream();
RTFEditorKit editorKit = new RTFEditorKit();
editorKit.write(out, textPane.getStyledDocument(), textPane.getSelectionStart() , textPane.getSelectionEnd() );
System.out.println("Test + " + out);
It always print the entire document and not the selected part of the document.
Where am I wrong ?
Thanks in advance
Nicolas
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!