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

JScrollPane's scroll bar policy does not work properly.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.1.4
    • client-libs
    • swing1.0fcs
    • x86
    • windows_nt



      Name: joT67522 Date: 11/10/97


      final java.lang.Object[][] data = {
          {"Mark", "Andrews", "red", "Baseball", "1"},
          {"Tom", "Ball", "Blue", "Football", "2"},
          {"Alan", "Chung", "Green", "Baseball", "3"},
          {"Jeff", "Dinkins", "Turquois", "Football", "4"},
          {"Amy", "Fowler", "Yellow", "Hockey", "5"}
      };

      JTable table = new JTable(data, new java.lang.Object[] {"Col 1","Col 2","Col 3","Col 4","Col 5"});

      JScrollPane scrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

      /*
      As indicated above, I instructed the scrollPane to NEVER show the vertical scroll bar,
      but the vertical scroll bar still shows up if the scroll pane is too small.
      */

      ===============

      I have tried the following test case on both JDK112 and JDK114. Even
      though I set
      the vertical scroll bar policy to NEVER, the vertical scroll bar still
      shows up when you
      decrease the size of the window.
      Here is the source code:
      -----------------------------

      import java.awt.*;
      import java.applet.*;
      import com.sun.java.swing.*;

      public class SPTest extends Applet
      {
          public SPTest()
          {
          }

          public void init()
          {
              final java.lang.Object[][] data = {
                  {"Mark", "Andrews", "red", "Baseball", "1"},
                  {"Tom", "Ball", "Blue", "Football", "2"},
                  {"Alan", "Chung", "Green", "Baseball", "3"},
                  {"Jeff", "Dinkins", "Turquois", "Football", "4"},
                  {"Amy", "Fowler", "Yellow", "Hockey", "5"}
              };

              final java.lang.Object[] header = {"Col 1",
                                                 "Col 2",
                                                 "Col 3",
                                                 "Col 4",
                                                 "Col 5"};

              JTable table = new JTable(data, header);

              JScrollPane scrollPane = new JScrollPane(
                  ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED
              );

              scrollPane.getViewport().add(table);
              this.setLayout(new BorderLayout());
              this.add(scrollPane, BorderLayout.CENTER);
          }

          static public void main(String[] args)
          {
              SPTest spTest = new SPTest();
              JFrame f = new JFrame();
              f.add(spTest, BorderLayout.CENTER);
              spTest.init();
              f.pack();
              f.setVisible(true);
          }
      }

      --------------------

      Then I run:
      java SPTest

      Then I resize (decrease the size) of the window. The vertical scroll
      bar shows up
      whenever the horizontal scroll bar shows up!

      Thanks for your help.
      Daniel

      (Review ID: 19049)
      ======================================================================

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: