How can I copy/paste contents of a TextComponent to/from the system clipboard while preserving the font attributes?

Sandip Chitale

Currently there is a bug which prevents you from getting anything other than String data from the clipboard. Please look at - http://developer.java.sun.com/developer/bugParade/bugs/4040183.html

What this means is that you could not use any binary format or serialized Java class (e.g. javax.swing.text.SimpleAttributeSet etc) as clipboard data.

This however does not mean you could not do what you want to do.

There are many text based attribute markup formats - the most well-known of them being the HTML. Thus you could encode the font information into a tag pairs. You should also set the DataFlavor mime type to "text/html" or may be "text/custom-html". You will have to do converion from/to the javax.swing.text.AttributeSet though.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact