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

getParent() returns wrong Container for Lightweight comp inside of ScrollPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.3
    • client-libs
    • sparc
    • solaris_2.5.1



      Name: joT67522 Date: 09/09/97


      When a lightweight component is added to ScrollPane
      and at one point it does getParent() call, getParent()
      java.awt.Panel[panel0,0,0,186x166,layout=java.awt.BorderLayout]
      not a ScrollPane.
      run the first program:
      import java.awt.*;
      import java.awt.event.*;
       
      public class MyFrame extends Frame
      {
              ScrollPane pane;
              class comp extends Component {
       
                      public comp(){}
                      public void paint(Graphics g) {
                              System.out.println(getParent());
                      }
              }
       
       
              public MyFrame() {
                      super();
                      add(pane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED));
                      pane.add(new comp());
              }
       
              public static void main(String [] args) {
                      MyFrame f = new MyFrame();
                      f.setSize(200,200);
                      f.setVisible(true);
              }
      }

      It will print:
      java.awt.Panel[panel0,0,0,186x166,layout=java.awt.BorderLayout]
      which is incorrect - it should print ScrollPane.


      Run second program which adds a heavyweight component
      to ScrollPane.
      import java.awt.*;
      import java.awt.event.*;
       
      public class GoodFrame extends Frame
      {
              ScrollPane pane;
              class comp extends Canvas{
       
                      public comp(){}
                      public void paint(Graphics g) {
                              System.out.println(getParent());
                      }
              }
       
       
              public GoodFrame() {
                      super();
                      add(pane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED));
                      pane.add(new comp());
              }
       
              public static void main(String [] args) {
                      GoodFrame f = new GoodFrame();
                      f.setSize(200,200);
                      f.setVisible(true);
              }
      }

      It will print correctly the parent of component:
      java.awt.ScrollPane[scrollpane0,5,25,190x170,ScrollPosition=(0,0),Insets=(2,2,2,2),ScrollbarDisplayPolicy=as-needed]
      company - AT&T , email - ###@###.###
      ======================================================================

            xdengsunw Xianfa Deng (Inactive)
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: