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

Scroll bar policy "ALWAYS" acts as "AS_NEEDED"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • None

      Run the application below. As it comes up, the TextArea is adorned with scroll bars, as it should be. As soon as you start typing, the scroll bars disappear - this should not happen. They come back when they are "needed", that is, when the text exceeds the visible space. Looks like "ALWAYS" is interpreted as "AS_NEEDED".

      /*
       * %W% %E%
       *
       * Copyright 1997-1998 by Sun Microsystems, Inc.,
       * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
       * All rights reserved.
       */

      import java.applet.Applet;
      import java.awt.Frame;
      import java.awt.GridLayout;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import java.awt.event.WindowListener;
      import javax.swing.JTextArea;
      import javax.swing.JScrollPane;
      import javax.swing.ScrollPaneConstants;

      public class PolicyTest extends Applet {

          public void init() {
              addComponents();
          }
          
          public void start() {
          }
          
          public void stop() {
          }
          
          public void addComponents() {
              setLayout(new GridLayout(1, 1, 10, 10));
              add(new JScrollPane(new JTextArea("Swing text component\n"),
                                  ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS));
          }

          public static void main(String argv[]) {
              final PolicyTest applet = new PolicyTest();
              applet.init();
              applet.start();
              makeFrame(applet, "Scroll Bar Policy Test");
          }

          public static void makeFrame(Applet applet, String title) {
              Frame frame = new Frame(title);
              frame.pack(); // adds peer
              frame.add("Center", applet);
              frame.setSize(400, 400);
              WindowListener listener = new AppletWindowListener(applet);
              frame.addWindowListener(listener);
              frame.pack();
              frame.show();
          }
      }

      class AppletWindowListener extends WindowAdapter {

          private Applet applet;

          AppletWindowListener(Applet applet) {
              this.applet = applet;
          }

          public void windowClosing(WindowEvent e) {
              e.getWindow().dispose();
              System.exit(0);
          }
      }

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            nlindenbsunw Norbert Lindenberg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: