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

JViewport.setViewPosition does not work on invalid components

XMLWordPrintable

    • Fix Understood
    • generic, x86
    • generic, windows_2000

      Name: gm110360 Date: 06/22/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      JViewport.setViewPosition does not work on invalid components

      When a component within a JScrollpane has been enlarged and hence is no longer valid, JViewport.setViewPosition incorrectly assumes that the Pane has been validated before it gets called. As a result it is changing the view position to be within the old invalid sizes.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the button text to be shown in the top left corner of the scroll pane (position 500, 500) of the button (like what would be shown with the line pane.validate(); uncommented
      ACTUAL -
      the view position has not been changed at all, it is almost at position 0,0

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class Test {
        public static void main(String s[]) {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          final JButton button = new JButton("Some Text");
          final JScrollPane pane = new JScrollPane(button);
          frame.add(pane);
          frame.setSize(200, 200);
          frame.setVisible(true);
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              button.setPreferredSize(new Dimension(1000, 1000));
              //pane.validate();
              pane.getViewport().setViewPosition(new Point(500, 500));
            }
          });
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      add the line pane.validate(); in every time before setViewPosition is called as shown in the source code
      (Incident Review ID: 280956)
      ======================================================================

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: