• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Copy/Paste in JTextPane

 
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
 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!