Click to email this message Click to edit this message...



Hi all,

I am writing a wysiwyg editor for html documents. I am using a JEditorPane with HTMLEditorKit.

When a user copies and pastes text, or if they highlight text and drag it, the text that they moved gets wrapped in all the css divs that were wrapping the entire document. So if I have a css border wrapping everything, copy and paste will produce three borders: a border around the top text, a border around the moved text, and a border around the bottom text.

The short self-contained example below illustrates what I mean. Try copying and pasting, or highlighting and dragging. The result is awful.

Anyone know how to gt it to copy just the text, and not all the div wrappings?

Thanks very much for any help!

Sam

Java Code:
import javax.swing.*;
import javax.swing.text.html.*;
 
public class SwingTester extends JFrame {
 
	public SwingTester() {
		JEditorPane editorPane = new JEditorPane();
		editorPane.setEditorKit(new HTMLEditorKit());
		editorPane.setEditable(true);
		
		String html = "<div style=\"background-color: green; padding: 5px\">" +
				"<div style=\"background-color: white;\">"+
				"test <p> test <p> test <p> test <p> test <p> test"+
				"</div>"+
				"</div>";
		
		editorPane.setText(html);
		
		this.getContentPane().add(editorPane);
	}
 
	public static void main(String[] args) {
		SwingTester st = new SwingTester();
		st.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		st.setSize(800, 600);
		st.setVisible(true);
	}
 
}