Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Copying from a JTextPane to Microsoft Word and preserving format

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out how, in code, to add color and fonts to my JTextPane.  But when I copied the text to a Microsoft Word document it only copied the text, not the formatting.  Is it possible to copy from a JTextPane to a Microsoft Word document or Outlook email with the colors and fonts preserved?  If so, how can this be accomplished?

Thanks in advance.
 
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see why not. You would have to go through the styled document and convert all of the text and styles that it contains to text and styles in MS Word format. There's an API from Apache POI which supports Word.
 
bobt Thompson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it to work using the RTFEditorKit.  I had to define my own copy to clipboard method.  Right now I have a button click event that calls this code.  If I want to implement Ctrl-C, Ctrl-V I'll have to override those keystrokes to call this code.  By default it just copies text.

Here is the code:

 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even better, if RTFEditorKit does what you need!
 
Rancher
Posts: 3232
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the DataHandler?

I don't see that class in the JDK 11 API.

It would be nice if you included that class so others could use it.

 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javax.activation classes were deprecated after Java 8 and it looks like you have to download the Java Activation Framework separately to get them.
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic