JDK-4706403 : 1.4.1 REGRESSION: HTML table width=100% ignored in JEditorPane in JScrollPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2002-06-21
  • Updated: 2002-06-27
  • Resolved: 2002-06-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.1 rcFixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description

Name: jk109818			Date: 06/21/2002


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)


FULL OPERATING SYSTEM VERSION :
glibc-2.2.4-24
Linux 2.4.9-31 #1 Tue Feb 26 07:11:02 EST 2002 i686 unknown
Red Hat Linux release 7.1 (Seawolf)

A DESCRIPTION OF THE PROBLEM :
The width=100% HTML table attribute is not respected in a
JEditorPane placed in a JScrollPane, i.e. the table does not
take up 100% of the available space.  It does work as
expected if the JEditorPane is not placed in a JScrollPane.
 It also worked as expected in JRE 1.4.0 and JRE 1.3.x

REGRESSION.  Last worked in version 1.4

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the HTMLTableBug.java (below)

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expect both HTML tables to occupy 100% of the available
horizontal space.

Result (for 1.4.1 beta) is that the html table in a
JScrollPane does not occupy 100% of the space.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class HTMLTableBug extends JFrame
{
  final String html = "<html>\n<body>\n<table border=1 width=100%
bgcolor=#ff0000><tr><td>test 1</td></tr></table>\n</body>\n</html>\n";

  public HTMLTableBug()
  {
    super("HTMLTableBug");

    JScrollPane scroll = new JScrollPane();
    JEditorPane pane = getPane();
    scroll.getViewport().add(pane);
    scroll.setBorder(new TitledBorder("With scrollpane"));

    pane = getPane();
    pane.setBorder(new TitledBorder("W/o scrollpane"));

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(scroll);
    panel.add(pane);
    panel.setPreferredSize(new Dimension(400, 400));
    getContentPane().add(panel);

    addWindowListener(new WindowEventHandler());
    pack();
    show();
  }

  JEditorPane getPane()
  {
    JEditorPane pane = new JEditorPane();
    pane.setContentType("text/html");
    pane.setText(html);
    
    return pane;
  }

  class WindowEventHandler extends WindowAdapter
  {
    public void windowClosing(WindowEvent e)
    {
      System.exit(0);
    }
  }

  public static void main(String[] args)
  {
    new HTMLTableBug();
  }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Don't use table % width tags...

Release Regression From : 1.4
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 153967) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: hopper-rc FIXED IN: hopper-rc INTEGRATED IN: hopper-rc
14-06-2004

SUGGESTED FIX --- HTMLEditorKit.java Mon Jun 24 13:31:35 2002 *************** *** 1208,1213 **** --- 1208,1214 ---- Insets insets = container.getInsets(); viewVisibleWidth = componentVisibleWidth - insets.left - getLeftInset(); widthStorage = targetSpan; + Object key = (axis == X_AXIS) ? CSS.Attribute.WIDTH : CSS.Attribute.HEIGHT; for (int i = 0; i < n; i++) { View v = getView(i); int min = (int) v.getMinimumSpan(axis); *************** *** 1215,1220 **** --- 1216,1231 ---- //try to use viewVisibleWidth if it is smaller than targetSpan //in case viewVisibleWidth smaller than min use min targetSpan = Math.min(widthStorage, Math.max(viewVisibleWidth, min)); + + // check for percentage span + AttributeSet a = v.getAttributes(); + CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(key); + if ((lv != null) && lv.isPercentage()) { + // bound the span to the percentage specified + min = (int) lv.getValue(targetSpan); + max = min; + } + if (max < targetSpan) { // can't make the child this wide, align it float align = v.getAlignment(axis); ###@###.### 2002-06-24
24-06-2002

EVALUATION This bug is a regression to 4321103. In that fix I did not handle percentage attributes properly. ###@###.### 2002-06-24
24-06-2002