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

html table using percentage widths is incorrect

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      J2SE 6.0 beta 2

      ADDITIONAL OS VERSION INFORMATION :
      windows xp sp 2
      mac ox 10.4.7

      A DESCRIPTION OF THE PROBLEM :
      When creating a table using <table width=100%>, and columns using a specified percentage width, the column size is calculated incorrectly, and teh columns widths are not the erquested percentage.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the supplied test case under both 1.4.2 and 1.5 or 1.6

      resize the window, notice how under 1.4.2 the columns remain aligned (the table is 100% and the colums are 20% and 80%), under the later versions the column widths vary based on content. Actually, what I think is happeneding is that tha


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Each column should remain at its requested percentage width regardless of content.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package tyler.empire.ui;

      import java.awt.Color;

      import javax.swing.*;
      import javax.swing.border.LineBorder;

      /**
      * test using a html table with % column widths
      */
      public class TestHtmlTableWidths {
            public static void main(String[] args) {
             SwingUtilities.invokeLater(new Runnable(){
                 public void run() {
                     new TestFrame();
                 }});
         }

         static class TestFrame extends JFrame {
                    public TestFrame() {
                 JTextPane p1 = new JTextPane();
                 JTextPane p2 = new JTextPane();
                 JTextPane p3 = new JTextPane();
                 JTextPane p4 = new JTextPane();
                            p1.setBorder(new LineBorder(Color.RED));
                 p2.setBorder(new LineBorder(Color.RED));
                 p3.setBorder(new LineBorder(Color.RED));
                 p4.setBorder(new LineBorder(Color.RED));
                            p1.setContentType("text/html");
                 p2.setContentType("text/html");
                 p3.setContentType("text/html");
                 p4.setContentType("text/html");
                            p1.setText("<html><table width=100%><tr><td width=80%>This is some text</td><td width=20% align=left>column #2</td></tr></table>");
                 p2.setText("<html><table width=100%><tr><td width=80%>smaller</td><td width=20% align=left>this is some much larger text in column #2</td></tr></table>");
                 p3.setText("<html><table width=100%>"+
                         "<tr><td width=80%>This is some text</td><td width=20% align=left>column #2</td></tr>"+
                         "<tr><td width=80%>smaller</td><td width=20% align=left>this is some much larger text in column #2</td></tr>"+
                         "</table>");
                 p4.setText("<html><table width=100%><tr><td width=80%>smaller</td><td width=20% align=left>this is really a lot of text in column #2 but it should still align the column with the component above</td></tr></table>");
                                       getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
                            getContentPane().add(p1);
                 getContentPane().add(p2);
                 getContentPane().add(p3);
                 getContentPane().add(p4);
                            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                            pack();
                 show();
             }
         }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      I think the offending code is ColumnIterator.getMinimumSpan() in javax.swing.text.html.TableView

      In 1.4.2, the method was:

      public float getMinimumSpan(float parentSpan) {
      if ((percentages != null) && (percentages[col] != 0)) {
      return Math.max(percentages[col], columnRequirements[col].minimum);
      }
      return columnRequirements[col].minimum;
      }

      In 1.5 the method is

      public float getMinimumSpan(float parentSpan) {
      // do not care for percentages, since min span can't
                  // be less than columnRequirements[col].minimum,
      // but can be less than percentage value.
      return columnRequirements[col].minimum;
      }

      I made the changes in a local copy and it worked correctly.

            idk Igor Kushnirskiy (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: