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

JTextPane has bad height (incorrect preferredSize)

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_0"
      OpenJDK Runtime Environment (build 1.6.0_0-b11)
      OpenJDK 64-Bit Server VM (build 1.6.0_0-b11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux scylla.ellipsis.cx 2.6.26.5-45.fc9.x86_64 #1 SMP Sat Sep 20 03:23:12 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
        Fix the width of a JTextPane, set it to have whatever height it prefers given that width, and put it into a JDialog which is then packed. Using OpenJDK, the JTextPane ends up with a lot of extra empty space below the text. This works properly with Sun Java 1.6.0_07-b06.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The dialog should be tight around the bottom of the text.
      ACTUAL -
      There is much extra space below the text.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.Insets;
      import java.awt.Frame;
      import javax.swing.JDialog;
      import javax.swing.JTextPane;
      import javax.swing.SwingUtilities;

      public class Test {
        public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              test();
            }
          });
        }

        private static void test() {
          final String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

          final JTextPane tp = new JTextPane();
          tp.setText(loremIpsum + "\n\n" + loremIpsum);
          tp.setEditable(false);
          
          final Dimension d = new Dimension(400, Integer.MAX_VALUE);
          tp.setSize(d);
          d.height = tp.getPreferredSize().height;
          tp.setPreferredSize(d);
       
          System.err.println(tp.getPreferredSize());

          final JDialog dialog = new JDialog((Frame) null, "Flow Label Test");
          dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
          dialog.add(tp);
          dialog.pack();
          dialog.setVisible(true);
        }
      }
      ---------- END SOURCE ----------

      Release Regression From : 6u7
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

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

              Created:
              Updated:
              Imported:
              Indexed: