-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
6u2, 6u10
-
x86, sparc
-
solaris_7, windows_xp
A Newline is inserted during Cut and Paste to HTMLEditorKit. The copy or paste is wrong. Newlines will be created breaking up the text.
This bug is found in all 6u10 and prior releases.
Run the attached source code.
1. Type "One Two Three" in the TextPane.
2. Copy the text "One".
3. Attempt to paste the copied text somewhere between the text "Two" and "Three".
import java.io.FileReader;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
public class ReplaceReader {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception evt) {}
JFrame f = new JFrame("JEditorPane with Custom Reader");
JEditorPane ep = new JEditorPane();
f.getContentPane().add(new JScrollPane(ep));
f.setSize(400, 300);
f.setVisible(true);
HTMLEditorKit kit = new HTMLEditorKit() {
public Document createDefaultDocument() {
HTMLDocument doc = new CustomHTMLDocument(getStyleSheet());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}
};
ep.setEditorKit(kit);
try {
Document doc = ep.getDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
kit.read(new FileReader(args[0]), doc, 0);
} catch (Exception e) {
System.out.println("Exception while reading HTML " + e);
}
}
}
class CustomHTMLDocument extends HTMLDocument {
CustomHTMLDocument(StyleSheet styles) {
super(styles);
}
public HTMLEditorKit.ParserCallback getReader(int pos) {
return new CustomReader(pos);
}
class CustomReader extends HTMLDocument.HTMLReader {
public CustomReader(int pos) {
super(pos);
}
}
}
This bug is found in all 6u10 and prior releases.
Run the attached source code.
1. Type "One Two Three" in the TextPane.
2. Copy the text "One".
3. Attempt to paste the copied text somewhere between the text "Two" and "Three".
import java.io.FileReader;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
public class ReplaceReader {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception evt) {}
JFrame f = new JFrame("JEditorPane with Custom Reader");
JEditorPane ep = new JEditorPane();
f.getContentPane().add(new JScrollPane(ep));
f.setSize(400, 300);
f.setVisible(true);
HTMLEditorKit kit = new HTMLEditorKit() {
public Document createDefaultDocument() {
HTMLDocument doc = new CustomHTMLDocument(getStyleSheet());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}
};
ep.setEditorKit(kit);
try {
Document doc = ep.getDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
kit.read(new FileReader(args[0]), doc, 0);
} catch (Exception e) {
System.out.println("Exception while reading HTML " + e);
}
}
}
class CustomHTMLDocument extends HTMLDocument {
CustomHTMLDocument(StyleSheet styles) {
super(styles);
}
public HTMLEditorKit.ParserCallback getReader(int pos) {
return new CustomReader(pos);
}
class CustomReader extends HTMLDocument.HTMLReader {
public CustomReader(int pos) {
super(pos);
}
}
}
- duplicates
-
JDK-6606169 Copy & Paste with formated text add additional newlines
-
- Closed
-
-
JDK-6721081 Extra lines in JEditorPane writing HTML tags
-
- Open
-