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

JTextPane throws Exception when trying to siwtch from text/html to text/plain

XMLWordPrintable

    • b20
    • generic, x86
    • generic, windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      When using the JTextPane and setting the contetnt type to text/html and then back to text/plain using the setContentType(String) method the JVM Throws a java.lang.IllegalArgumentException



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a JTextPane;
      2. change the content type to text/html (possibly others as well);
      3. change the content type back to text/plain (using the setContentType("text/plain") method).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the JTextPane should set the content type back to text/plain.
      ACTUAL -
      An Exception occurs.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalArgumentException: Must be StyledEditorKit
      at javax.swing.JTextPane.setEditorKit(Unknown Source)
      at javax.swing.JEditorPane.setContentType(Unknown Source)
      at Tester.main(Tester.java:19)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Tester {
        public static void main(String[] args) {
          javax.swing.JFrame f = new javax.swing.JFrame();
          javax.swing.JTextPane pane = new javax.swing.JTextPane();
          f.getContentPane().add(pane);
          pane.setContentType("text/html");
          pane.setText("blabla");
          pane.setContentType("text/plain");
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use
      setEditorKit(new StyledEditorKit());
      instead of
      setContentType("text/plain");

            idk Igor Kushnirskiy (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: