Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6723267

Newline inserted during Cut and Paste to HTMLEditorKit

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6u2, 6u10
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_7, windows_xp

      Description

      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);
          }
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peterz Peter Zhelezniakov (Inactive)
                Reporter:
                kevibrow Kevin Brown
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: