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

a JTextField in gridBagLayout does not properly set MinimumSize

    XMLWordPrintable

Details

    • Fix Understood
    • generic, x86
    • generic, linux

    Description

      Name: vi73552 Date: 05/17/99


      /* The following class generates a typical use case for swing. A label and two textfields, which display the length of the requested input.
      When there is enough space, everything works fine. But if you narrow the frame so that there is not enough width for the columns of the textfields, both textfields will be crippled to their minimal size although more room is left.
      That was not the case in swing 1.0.1 and I think the patch for bug 4118855 is the reason for that.
      I think it is correct that JTextfield doesn't return its preferredSize as minimumSize. But it is a bug, that gridBagLayout calculates with minimumSize when there is not enough space for preferredSize.*/

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.event.*;

      public class GridBagTest{

        public static void main (String[] args){

          JFrame frame = new JFrame();
          frame.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e){
              System.exit(0);
            }
          });

          Container container = frame.getContentPane();
          container.setLayout(new GridBagLayout());
          GridBagConstraints gBC = new GridBagConstraints();

          gBC.gridx = 0;
          gBC.gridy = 0;
          gBC.gridwidth = 1;
          gBC.gridheight = 1;
          gBC.weightx = 0.0;
          gBC.weighty = 0.0;
          gBC.fill = GridBagConstraints.NONE;
          gBC.anchor = GridBagConstraints.NORTHWEST;
          container.add(new JLabel("Text"), gBC);

          gBC.gridx = 1;
          gBC.gridy = 0;
          gBC.gridwidth = 1;
          gBC.gridheight = 1;
          gBC.weightx = 1.0;
          gBC.weighty = 0.0;
          gBC.fill = GridBagConstraints.NONE;
          gBC.anchor = GridBagConstraints.NORTHWEST;
          container.add(new JTextField(16), gBC);

          gBC.gridx = 1;
          gBC.gridy = 1;
          gBC.gridwidth = 1;
          gBC.gridheight = 1;
          gBC.weightx = 1.0;
          gBC.weighty = 0.0;
          gBC.fill = GridBagConstraints.NONE;
          gBC.anchor = GridBagConstraints.NORTHWEST;
          container.add(new JTextField(8), gBC);

          frame.pack();
          frame.setVisible(true);
        }
      }

      /* Do not tell me to use fill, I wan't the textfields two have different widths.*/
      (Review ID: 63228)
      ======================================================================

      Name: krC82822 Date: 11/28/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      We've got an application which has some custom database connected JTextFields.
      The columns property of the JTextFields is set to the columnDisplaySize of the
      ResultSetMetaData. The panels primarily use GridBagLayout as the LayoutManager.
      Sometimes there isn't enough room for a JTextField to have the size of it's
      preferredSize. What the GridBagLayout manager then does is just reduce it's
      size to the minimumSize! This is totally unacceptable (minimumSize doesn't
      allow for display of a single character!).
      What we expect to see is that GridBagLayout gives the available space (smaller
      than the preferredSize but greater than the minimumSize) to the JTextField!

      There is a bug about this exact problem already on the Bug Parade: 4238932, but
      in the evaluation, the ball is first passed to the AWT group and then passed
      back to the Swing group. This does not help us (developers) very much.

      Please fix this or provide a workaround. The only workaround we currently can
      think of is to just manually set the minimumSize of the JTextField's (ugly &
      platform dependant).
      (Review ID: 112859)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              dav Andrei Dmitriev (Inactive)
              vasya Vassili Igouchkine (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: