JDK-4222731 : Swing 1.2 produces invalid html content
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-03-22
  • Updated: 1999-05-14
  • Resolved: 1999-05-14
Related Reports
Duplicate :  
Description

Name: gsC80088			Date: 03/22/99


The construction of HTML content by a applet running under the Java Plugin 1.2 
does not properly interpret the incoming html.  Attached are the results of an 
attempt to construct a simple html table and display it in either a JTextPane or 
a JEditorPane (either produce the same results).  Also attached is the applet code.
  Similar kinds of misplacement of input in the document structure can be found 
with content other than tabular.

While it's true that some further progress can be made if this bug is not fixed,
 it certainly causes a great deal of workaround to avoid what would be a very
 elegant solution.

Pressing the "build" button in the applet results in this:

Exception occurred during event dispatching:
java.lang.Error: Can't build a tr, BranchElement(tr) 6,7
	at javax.swing.text.html.HTMLEditorKit$HTMLFactory.create(HTMLEditorKit.java:705)
	at javax.swing.text.CompositeView.loadChildren(Compiled Code)
	at javax.swing.text.CompositeView.setParent(CompositeView.java:153)
	at javax.swing.text.CompositeView.replace(Compiled Code)
	at javax.swing.text.BoxView.replace(BoxView.java:68)
	at javax.swing.text.CompositeView.loadChildren(Compiled Code)
	at javax.swing.text.CompositeView.setParent(CompositeView.java:153)
	at javax.swing.plaf.basic.BasicTextUI$RootView.setView(BasicTextUI.java:894)
	at javax.swing.plaf.basic.BasicTextUI.setView(BasicTextUI.java:375)
	at javax.swing.plaf.basic.BasicTextUI.modelChanged(BasicTextUI.java:363)
	at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.propertyChange(BasicTextUI.java:1349)
	at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(Compiled Code)
	at javax.swing.JComponent.firePropertyChange(Compiled Code)
	at javax.swing.text.JTextComponent.setDocument(JTextComponent.java:314)
	at styledHTMLDoc.Applet1.jButton1_mouseClicked(Applet1.java:113)
	at styledHTMLDoc.Applet1_jButton1_mouseAdapter.mouseClicked(Applet1.java:145)
	at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:211)
	at java.awt.Component.processMouseEvent(Component.java:3129)
	at java.awt.Component.processEvent(Component.java:2965)
	at java.awt.Container.processEvent(Container.java:987)
	at java.awt.Component.dispatchEventImpl(Compiled Code)
	at java.awt.Container.dispatchEventImpl(Compiled Code)
	at java.awt.Component.dispatchEvent(Compiled Code)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:1747)
	at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
	at java.awt.Container.dispatchEventImpl(Compiled Code)
	at java.awt.Component.dispatchEvent(Compiled Code)
	at java.awt.EventQueue.dispatchEvent(Compiled Code)
	at java.awt.EventDispatchThread.run(Compiled Code)
Exception occurred during event dispatching:
java.lang.NullPointerException: 
	at javax.swing.text.html.BlockView.getAlignment(BlockView.java:103)
	at javax.swing.text.BoxView.getChildRequests(Compiled Code)
	at javax.swing.text.BoxView.layoutMajorAxis(BoxView.java:708)
    at javax.swing.text.BoxView.layout(Compiled Code)
	at javax.swing.text.BoxView.setSize(BoxView.java:151)
	at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1264)
	at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:549)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:705)
	at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:934)
	at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:745)
	at java.awt.Container.layout(Compiled Code)
	at java.awt.Container.doLayout(Compiled Code)
	at java.awt.Container.validateTree(Compiled Code)
	at java.awt.Container.validate(Container.java:532)
	at javax.swing.RepaintManager.validateInvalidComponents(Compiled Code)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:184)
	at javax.swing.SystemEventQueueUtilities.processRunnableEvent(SystemEventQueueUtilities.java:354)
	at javax.swing.SystemEventQueueUtilities.access$0(SystemEventQueueUtilities.java:350)
	at javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(SystemEventQueueUtilities.java:391)
	at java.awt.Component.dispatchEventImpl(Compiled Code)
	at java.awt.Component.dispatchEvent(Compiled Code)
	at java.awt.EventQueue.dispatchEvent(Compiled Code)
	at java.awt.EventDispatchThread.run(Compiled Code)

Then, pressing the "show" button in the applet results in this:

<html>
  <head>
  <title>Swing 1.1.1 Beta1 API Specification: Class HTMLEditorKit  </title>
  </head>
  

  <body>
    <table>
      
    </table>
    <tr>
      
    </tr>
    <td>
      
    </td>
    cell a1

    <td>
      
    </td>
    <td>
      
    </td>
    cell a2

    <td>
      
    </td>
    <tr>
      
    </tr>
    <tr>
      
    </tr>
    <td>
      
    </td>
    cell b1

    <td>
      
    </td>
    <td>
      
    </td>
    cell b2

    <td>
      
    </td>
    <tr>
      
    </tr>
    <table>
      
    </table>
  </body>
</html>


Code producing the above results:

package styledHTMLDoc;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import borland.jbcl.layout.*;
import java.io.*;
import java.net.*;
import com.inprise.jbcl.control.*;

public class Applet1 extends JApplet {

  HyperlinkListener hl = new HyperlinkListener () {
    public void hyperlinkUpdate(HyperlinkEvent e) {
      System.out.println(e.getURL() );
    }
  };
  boolean isStandalone = false;
  javax.swing.text.html.HTMLEditorKit ek = new javax.swing.text.html.HTMLEditorKit();
  javax.swing.text.html.HTMLDocument htmlDoc = new javax.swing.text.html.HTMLDocument();
//  javax.swing.JTextPane jpane = new javax.swing.JTextPane();
  javax.swing.JEditorPane jpane = new javax.swing.JEditorPane();
  javax.swing.JButton jButton1 = new javax.swing.JButton();
  javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
  javax.swing.JButton jButton2 = new javax.swing.JButton();
  javax.swing.JPanel jPanel2 = new javax.swing.JPanel();
  BorderLayout borderLayout1 = new BorderLayout();

  //Construct the applet

  public Applet1() {
  }

  public void init() {
    try {
        jbInit();
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    jpane.addHyperlinkListener(hl);

  }

  private void jbInit() throws Exception {
    this.setSize(400,300);
    this.getContentPane().setLayout(borderLayout1);
    jpane.setBackground(Color.white);
    jpane.setEditorKit(ek);
    this.setEnabled(true);
    jpane.setForeground(Color.black);
    jpane.setEditable(false);
    jButton1.setText("build");
    jButton1.setContentAreaFilled(false);
    jButton1.setOpaque(true);
    jButton1.setDoubleBuffered(true);
    jButton2.setText("show");
    jButton2.addMouseListener(new Applet1_jButton2_mouseAdapter(this));
    jButton1.addMouseListener(new Applet1_jButton1_mouseAdapter(this));
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jpane, null);
    this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
    jPanel2.add(jButton1, null);
    jPanel2.add(jButton2, null);
  }

  public String getAppletInfo() {
    return "Applet Information";
  }

  public String[][] getParameterInfo() {
    return null;
  }

  void jButton1_mouseClicked(MouseEvent e) {
    htmlDoc = new HTMLDocument();

    try {
      htmlDoc = new HTMLDocument();
      StringBuffer sb = new StringBuffer(50);
      sb.append("<HEAD><TITLE>Swing 1.1.1 Beta1 API Specification: Class  HTMLEditorKit</TITLE></HEAD>");
      sb.append("<BODY>");
      sb.append("<TABLE>");
      sb.append("<TR>");
      sb.append("<TD>cell a1</TD>");
      sb.append("<TD>cell a2</TD></TR>");
      sb.append("<TR>");
      sb.append("<TD>cell b1</TD>");
      sb.append("<TD>cell b2</TD></TR>");
      sb.append("</TABLE>");
      sb.append("</BODY>");
      StringReader sr = new StringReader(sb.toString());
      ek.read(sr, htmlDoc, 0);
      jpane.setDocument(htmlDoc);
    }
    catch (Exception ex) {
      System.out.println(ex);
    }
    jpane.invalidate();
    jpane.validate();
    jpane.repaint();
  }

  void jButton2_mouseClicked(MouseEvent e) {
    StringWriter sw = new StringWriter();
    try {
      ek.write(sw, htmlDoc, 0, htmlDoc.getLength());
    }
    catch (Exception ex) {
      System.out.println(ex);
    }
    System.out.println(sw);
  }

}

class Applet1_jButton1_mouseAdapter extends java.awt.event.MouseAdapter {
  Applet1 adaptee;


  Applet1_jButton1_mouseAdapter(Applet1 adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButton1_mouseClicked(e);
  }
}

class Applet1_jButton2_mouseAdapter extends java.awt.event.MouseAdapter {
  Applet1 adaptee;


  Applet1_jButton2_mouseAdapter(Applet1 adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButton2_mouseClicked(e);
  }
}
(Review ID: 55847) 
======================================================================

Comments
EVALUATION This is a result of the parser not being loaded correctly. Refer to 4181905 for more info. scott.violet@eng 1999-05-14
14-05-1999

PUBLIC COMMENTS This is a result of the parser not being loaded correctly. Refer to 4181905 for more info. scott.violet@eng 1999-05-14
14-05-1999