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

BoxLayout sizes Components wrong if minimumSize is larger than preferredSize

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.2
    • 1.1.6, 1.2.0
    • client-libs
    • 1.2.2
    • x86
    • windows_nt

      With BoxLayout, if a Component's minimumSize is larger than its preferredSize, when the window is packed one dimension receives the minimumSize, while the other dimension receies the preferredSize.

      Run the following application, and you'll see that the oval's drawn with a width larger than it should be.

      Having the minimumSize larger than the preferredSize is highly atypical, but it should still behave reasonably.


      //------------------------SizeTest.java------------------------------
      import java.awt.*;
      import com.sun.java.swing.*;
      //import java.awt.swing.*;

      public class SizeTest
      {
          static public void main(String args[])
          {
              JDialog dialog = new JDialog();
              Container pane = dialog.getContentPane();
              pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
              pane.add(new XComponent());
              dialog.pack();
              dialog.show();
          }
      }

      class XComponent extends JComponent
      {
          public Dimension getPreferredSize() {
              System.out.println("getPreferredSize");
              return new Dimension(150,150);
          }
          public Dimension getMinimumSize() {
              System.out.println("getMinimumSize");
              return new Dimension(200,200);
          }

          public void paintComponent(Graphics g) {
              Dimension d = getSize();
              g.drawOval(0,0,d.width-1,d.height-1);
          }
      }

            tprinzing Tim Prinzing (Inactive)
            bklocksunw Brian Klock (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: