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

JTable is not stretched to fill a viewport's hieght

XMLWordPrintable

    • b53
    • generic, x86
    • generic, windows_nt

      Name: krT82822 Date: 02/07/2000


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

        Bug was introduced in Swing 1.1, JDK 1.2

      The bug manifests itself like this:
      The background color is not painted correctly when JTable is in a
      JScollPane and the size of the table is smaller than the scrollpane.

      The bug is that ViewportLayout in Swing1.1, JDK1.2 and JDK1.3 does not
      stretch the component correctly. This used to work in Swing 1.0.3.

      This attached code illustrates the problem and has a fix.
      Related bugs: 4237176, 4119459, 4156773, 4189341

      This bug does not effect JList, only JTable, because of this difference
      in the implementation of Scrollable: (this is another workaround)

      JList.java:
          /**
           * Returns true if this <code>JList</code> is displayed in a
           * <code>JViewport</code> and the viewport is taller than
           * <code>JList</code>'s preferred height; otherwise returns false.
           * If false, then don't track the viewport's height. This allows vertical
           * scrolling if the <code>JViewport</code> is itself embedded in a
           * <code>JScrollPane</code>.
           *
           * @return true if viewport is taller than <code>Jlist</code>'s
           * preferred height, otherwise false
           * @see Scrollable#getScrollableTracksViewportHeight
           */
          public boolean getScrollableTracksViewportHeight() {
      if (getParent() instanceof JViewport) {
      return (((JViewport)getParent()).getHeight() > getPreferredSize
      ().height);
      }
      return false;
          }



          /**
           * Returns false to indicate that the height of the viewport does not
           * determine the height of the table.
           *
           * @return false
           * @see Scrollable#getScrollableTracksViewportHeight
           */
          public boolean getScrollableTracksViewportHeight() {
              return false;
          }
      (Review ID: 100892)
      ======================================================================

            shickeysunw Shannon Hickey (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: