Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem copying HTML from JEditorPane to external applications
    primarykey
    data
    text
    <p>I'm having trouble copying HTML from JEditorPane to system clipboard and then pasting into other applications:</p> <ul> <li>OpenOffice 3.2 - Says "Requested clipboard format isn't available"</li> <li>Thunderbird 3.13 - Does nothing on paste</li> <li>Firefox 3.6.9 - Accepts plain text but for example in GMail "Compose mail" does nothing on paste</li> </ul> <p>I'm running WinXP by the way. In other applications like text-editors, MS Outlook, MS Word etc. it works as expected, ie I get plain text with HTML tags stripped or formatted text according to which mimetype the application wants.</p> <p>Anyone has an idea what's wrong? Is it a problem in Swing or in OpenOffice/Mozilla?</p> <p>See test application below and try out. I've also tried with a custom <em>Transferable</em> but as soon as I provide a <em>DataFlavor</em> with mimetype="text/html" it stops to work in applications mentioned above.</p> <pre><code>import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; /** * Demonstrates problem with copy/paste between JEditorPane and OpenOffice/Thunderbird/Firefox. * * @author martin */ public class HtmlCopyDemo extends JFrame { public HtmlCopyDemo() { setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout()); setSize(400, 400); final JEditorPane editor = new JEditorPane(); editor.setContentType("text/html"); editor.setText("&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Here's some &lt;b&gt;formatted&lt;/b&gt; &lt;i&gt;text&lt;/i&gt;&lt;/body&gt;&lt;/html&gt;"); add(editor, BorderLayout.CENTER); JPanel panel = new JPanel(new FlowLayout()); add(panel, BorderLayout.NORTH); JButton button = new JButton("Copy"); panel.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editor.selectAll(); editor.copy(); } }); final JComboBox combo = new JComboBox(new Object[]{"text/html", "text/plain"}); panel.add(combo); combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = editor.getText(); editor.setContentType((String) combo.getSelectedItem()); editor.setText(text); } }); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new HtmlCopyDemo().setVisible(true); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload