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

Extra lines in JEditorPane writing HTML tags

    Details

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

      Description

      FULL PRODUCT VERSION :
      sun-java6-jdk 6-06-0 ubuntu1
      openjdk-6-jre 6b09-0 ubuntu2

      ADDITIONAL OS VERSION INFORMATION :
      UBUNTU 8.04 Linux 2.6.24.19.21.

      A DESCRIPTION OF THE PROBLEM :
      I wrote a little program for testing the HTML tags. I used two JEditorPane objects. One is on foreground listing the texts and one is a hidden object only for creating one text (one sentence). I used this hidden EditorPane, because there is no memberfunction add() by JEditorPane. So I can add a sentence to the written sentences on showed JEditorPane with using of copy/paste functions.
      I wrote some very similar sentences and I could see that there is an extra line between the first and second sentences.
      The HTML tags had a <br> on end of String. I erased them, after this action I could see the sentences without an extra line, but is not understandable for me, why the sentences are in separeted line. They must be after each other directly not under each other. I think. So the copy/paste functions inserts an extra line always, thet the programmers do not want.
      So if the sentences have <br>, the JeditorPane can show the first <br>, but the others not!
      And if I wrote only one line in JeditorPane I could not see the caret (cursor).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1, Write the attached codes in your IDE.
      2, Compile the programs.
      3, Show the results.
      4, Fix the bug.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1, If I have <br> in sentences, I must see after the first sentences no any extra line.
      2, If I do not have <br> in sentences, I must see directly after each other?
      3, If I write only one sentence, do not hide the carret (cursor).
      ACTUAL -
      1, If I have <br> in sentences, I can see after the first sentences one extra line, but after the other sentences not.
      2, If I do not have <br> in sentences, why the sentences are under each other. Why not after each other?
      3, If I write only one sentence the caret hides.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No any.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      1, The first original version:
      import java.awt.*;
      import javax.swing.*;

      public class HtmlFormating extends JFrame {
          String[] data = new String[] {"Joseph", "Hello!", "John", "Szia!"};
          String newMessage1 = "<b>" + data[0] + "</b> sent: <font size=\"4\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font><br>";
          String newMessage2 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"red\">" + data[3] + "</font><br>";
          String newMessage3 = "<b>" + data[0] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[3] + "</font><br>";
          String newMessage4 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font><br>";
          JEditorPane editor = new JEditorPane();
          JEditorPane hiddenEditor = new JEditorPane();

          public HtmlFormating() {
              super("Html Formating Example");
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setBounds(50, 50, 500, 500);
              getContentPane().add(new JScrollPane(editor));
              editor.setContentType("text/html");
              hiddenEditor.setContentType("text/html");
              writeText();
              setVisible(true);
          } // end of HtmlFormating()
          
          private int getLast(JEditorPane ep) {
              return ep.getDocument().getLength();
          } // end of getLast()
          
          public void writeHtmlString(String s) {
              int i = getLast(editor);
              hiddenEditor.setText(s);
              hiddenEditor.select(1, getLast(hiddenEditor));
              hiddenEditor.cut();
              editor.paste();
              editor.setCaretPosition(getLast(editor));
          } // end of writeHtmlString()
          
          public void writeText() {
              for (int i = 0; i < 10; i++) {
                  writeHtmlString(newMessage1);
                  writeHtmlString(newMessage2);
                  writeHtmlString(newMessage3);
                  writeHtmlString(newMessage4);
              }
          } // end of writeText()
          
          public static void main(String[] args) {
              HtmlFormating myForm = new HtmlFormating();
          }
          
      } // end of class

      ------------------------------------------------------------------------------------------------------------------------------------------
      2, The second version without <br>

      import java.awt.*;
      import javax.swing.*;

      public class HtmlFormating extends JFrame {
          String[] data = new String[] {"Joseph", "Hello!", "John", "Szia!"};
          String newMessage1 = "<b>" + data[0] + "</b> sent: <font size=\"4\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font>";
          String newMessage2 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"red\">" + data[3] + "</font>";
          String newMessage3 = "<b>" + data[0] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[3] + "</font>";
          String newMessage4 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font>";
          JEditorPane editor = new JEditorPane();
          JEditorPane hiddenEditor = new JEditorPane();

          public HtmlFormating() {
              super("Html Formating Example");
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setBounds(50, 50, 500, 500);
              getContentPane().add(new JScrollPane(editor));
              editor.setContentType("text/html");
              hiddenEditor.setContentType("text/html");
              writeText();
              setVisible(true);
          } // end of HtmlFormating()
          
          private int getLast(JEditorPane ep) {
              return ep.getDocument().getLength();
          } // end of getLast()
          
          public void writeHtmlString(String s) {
              int i = getLast(editor);
              hiddenEditor.setText(s);
              hiddenEditor.select(1, getLast(hiddenEditor));
              hiddenEditor.cut();
              editor.paste();
              editor.setCaretPosition(getLast(editor));
          } // end of writeHtmlString()
          
          public void writeText() {
              for (int i = 0; i < 10; i++) {
                  writeHtmlString(newMessage1);
                  writeHtmlString(newMessage2);
                  writeHtmlString(newMessage3);
                  writeHtmlString(newMessage4);
              }
          } // end of writeText()
          
          public static void main(String[] args) {
              HtmlFormating myForm = new HtmlFormating();
          }
          
      } // end of class

      ------------------------------------------------------------------------------------------------------------------------------------------

      3, The third version: with only one sentence

      import java.awt.*;
      import javax.swing.*;

      public class HtmlFormating extends JFrame {
          String[] data = new String[] {"Joseph", "Hello!", "John", "Szia!"};
          String newMessage1 = "<b>" + data[0] + "</b> sent: <font size=\"4\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font><br>";
          String newMessage2 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"red\">" + data[3] + "</font><br>";
          String newMessage3 = "<b>" + data[0] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[3] + "</font><br>";
          String newMessage4 = "<b>" + data[2] + "</b> sent: <font size=\"2\" face=\"Tahoma\" color=\"black\">" + data[1] + "</font><br>";
          JEditorPane editor = new JEditorPane();
          JEditorPane hiddenEditor = new JEditorPane();

          public HtmlFormating() {
              super("Html Formating Example");
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setBounds(50, 50, 500, 500);
              getContentPane().add(new JScrollPane(editor));
              editor.setContentType("text/html");
              hiddenEditor.setContentType("text/html");
              writeText();
              setVisible(true);
          } // end of HtmlFormating()
          
          private int getLast(JEditorPane ep) {
              return ep.getDocument().getLength();
          } // end of getLast()
          
          public void writeHtmlString(String s) {
              int i = getLast(editor);
              hiddenEditor.setText(s);
              hiddenEditor.select(1, getLast(hiddenEditor));
              hiddenEditor.cut();
              editor.paste();
              editor.setCaretPosition(getLast(editor));
          } // end of writeHtmlString()
          
          public void writeText() {
              writeHtmlString(newMessage1);
          } // end of writeText()
          
          public static void main(String[] args) {
              HtmlFormating myForm = new HtmlFormating();
          }
          
      } // end of class
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peterz Peter Zhelezniakov (Inactive)
                Reporter:
                ndcosta Nelson Dcosta
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: