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

JScrollBar.getMinimumSize() breaks the contract of JComponent.setMinimumSize()

XMLWordPrintable

    • b11
    • sparc
    • solaris_2.5.1

      The javadoc contract for JComponent.setMinimumSize(Dimension) states:

      "Sets the minimum size of this component to a constant value. Subsequent calls to getMinimumSize will always return this value..."

      However, JScrollBar overrides getMinimumSize() and breaks this contract - it always returns a minimum size derived from the preferred size even if you have previously called setMinimumSize().

      Code to reproduce:

      JScrollBar bar = new JScrollBar( SwingConstants.HORIZONTAL );
      bar.setMinimumSize( new Dimension( 75, 0 ) );
      System.out.println( bar.getMinimumSize() );

      Expected: Prints "java.awt.Dimension[width=75,height=0]"
      Actual: Prints "java.awt.Dimension[width=5,height=17]"

      The code for JScrollBar.java contains this comment above the implementation of getMinimumSize():

      // PENDING(hmuller) - the next three methods should be removed

      Indeed, removing those three methods would fix this bug.

        1. Aqua-maxsize.png
          Aqua-maxsize.png
          207 kB
        2. JScrollBarMaxLayout.java
          1 kB
        3. JScrollBarMinLayout.java
          1 kB
        4. Metal-minsize.png
          Metal-minsize.png
          15 kB
        5. Nimbus-maxsize.png
          Nimbus-maxsize.png
          34 kB
        6. Nimbus-min.png
          Nimbus-min.png
          32 kB
        7. ScrollbarSize.java
          3 kB
        8. Windows-maxsize.png
          Windows-maxsize.png
          15 kB
        9. Windows-minsize.png
          Windows-minsize.png
          15 kB

            psadhukhan Prasanta Sadhukhan
            mmma Marvin Ma (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: