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

REGRESSION: GridBagLayout handles ipadx differently under JDK 1.5

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 5.0
    • client-libs



      Name: gm110360 Date: 02/09/2004


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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      A form built with a GridBagLayout in such a way so that the left column, holding JLabels, remains at a fixed width, while the right column, containing JTextFields, grows and shrinks horizontally as the form is resized horizontally, does not work the same in 1.5 beta as previous versions. If a GridBagConstraints.ipadx value is used in the right column with each JTextFields to give them a minimum width when empty greater than they normally would have, the GridBagLayout does not allow them to shrink below this mininum width, instead shrinking the JLabels.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample program below under both 1.4.2 and 1.5 beta and see the differing behaviors.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect the form to initially be a size such that the JTextFields are about 300 pixels wide, and the System.out.println to produce this output:

      Frame size: java.awt.Dimension[width=385,height=297]


      ACTUAL -
      The form is 300 pixels wider than expected (300 is the value used for ipadx, BTW), and the console output is:

      Frame size: java.awt.Dimension[width=685,height=297]


      REPRODUCIBILITY :
      This bug can be reproduced always.

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


      public class GridBagBug {


          public static void main(String[] args) {

              JPanel p = new JPanel();
              p.setLayout(new GridBagLayout());
              p.setBorder(new EmptyBorder(10, 10, 10, 10));
              GridBagConstraints gc = new GridBagConstraints();
              Insets labelInsets = new Insets(0,0,0,0);
              Insets fieldInsets = new Insets(0,5,5,0);

              gc.anchor = gc.NORTH;
              gc.fill = gc.HORIZONTAL;

              for(int row=0; row<10; row++) {
                  JLabel label = new JLabel("Label " + (row+1));
                  // add the JLabel
                  gc.gridx = 0;
                  gc.gridy = row;
                  gc.weightx = 0;
                  gc.ipadx = 0;
                  gc.ipady = 0;
                  gc.insets = labelInsets;

                  p.add(label, gc);
                  label.setHorizontalAlignment(JLabel.RIGHT);

                  // now add the JTextField
                  gc.gridx = 1;
                  gc.weightx = 1;
                  gc.ipadx = 300;
                  gc.insets = fieldInsets;

                  p.add(new JTextField(), gc);
              }

              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(3);
              frame.setContentPane(p);
              frame.pack();
              frame.setVisible(true);
              System.out.println("Frame size: " + frame.getSize());
               
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      I haven't found one yet, but I suspect it will involve using something other than ipadx to give the JTextFields a starting width greater than their default minimum width.

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

      (Incident Review ID: 237702)
      ======================================================================

            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: