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

Panels stacked on top of an already displayed frame don't display correctly, if

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1
    • client-libs
    • None
    • sparc
    • solaris_2.5.1



      Name: mc57594 Date: 03/06/97


      See attached Source.

      Solaris displays differently to Win95.
      Application should put up 9 pannels on top of each other and then remove them one at a time. It then should put them up again, this time under each other and then remove them.

      Windows 95 does this fine (except for crashing if you run it more than once, as reported as a bug separately). Solaris dos not display anything until the first remove, and then it can be seen that both times it has put them up under each other.

      import java.awt.*;

      public class Test2 extends Object
      {
      public static Frame frame = null;

      public Test2()
      {
      super();
      }

      public static void main(String args[])
      {
      frame = new Frame("Test");
      frame.setLayout(new Xy(500,250));



      frame.setSize(500,250);

      frame.show();

      putEmUp(true);
      pullEmDown(true);

      putEmUp(false);
      pullEmDown(false);

      sleep(5);
      System.exit(0);
      }

      private static void putEmUp(boolean onTop)
      {
      Panel p = null;
      int vectorPos;

      if(onTop)
      vectorPos = 0;
      else
      vectorPos = -1;

      for(int i = 1;i < 10 ;i++)
      {
      p = new Panel(new Xy(40,20));
      p.add(new Button(".."+i+".."),new Point(1,1),0);

      frame.add(p,new Point(i,i),vectorPos);

      p.addNotify();
      frame.validate();

      System.out.println("Added " + i);
      sleep(1);
      }
      System.out.println("All up");
      }

      private static void pullEmDown(boolean onTop)
      {
      for(int i = 1;i < 10 ;i++)
      {
      sleep(1);
      if(onTop)
      frame.remove(0);
      else
      frame.remove(10 - (i + 1));

      frame.validate();

      System.out.println("Removed " + i);

      }

      System.out.println("All down");

      }

      public static void sleep(int time)
      {
      for(int i = 0; i <= 1000000 * time; i++)
      {
      }

      }

      }

      import java.awt.*;
      import java.util.*;

      public class Xy implements LayoutManager2
      {
      protected Vector dimensions = new Vector(0,1);
      protected Vector components = new Vector(0,1);
         protected int width = 0;
         protected int height = 0;

         public Xy()
          {
      super();
          }

         public Xy(int aWidth, int aHeight)
          {
      super();

           width = aWidth;
           height = aHeight;
          }


      public void addLayoutComponent(Component component, Object constraints)
          {
          int x = ((Point)constraints).x;
      int y = ((Point)constraints).y;

           if ((x < 0) || (y < 0))
      {
             return;
      }


      dimensions.addElement(new Dimension(x, y) );
      components.addElement(component);
         }

         
      public void addLayoutComponent(String name, Component component)
          {
           int i = name.indexOf(" ");

           if (i == -1)
           {
             return;
           }

           int x = Integer.valueOf( name.substring(0, i), 10 ).intValue();
           int y = Integer.valueOf( name.substring(i + 1, name.length()), 10 ).intValue();
          
           if ((x < 0) || (y < 0))
      {
             return;
      }


      dimensions.addElement(new Dimension(x, y) );
      components.addElement(component);
          }


         public void removeLayoutComponent(Component component)
          {
           int i = components.indexOf(component);

           try
      {
             components.removeElementAt(i);
             dimensions.removeElementAt(i);
            }
            catch (ArrayIndexOutOfBoundsException e)
            {
             System.err.println("Internal Syncronyzation Error :" + e);
            }

          }


        public Dimension minimumLayoutSize(Container parent)
          {
           Insets insets = parent.getInsets();
           return new Dimension(width + insets.left + insets.right, height + insets.top + insets.bottom);
          }

         public Dimension preferredLayoutSize(Container parent)
          {
      return minimumLayoutSize(parent);
        }

        public Dimension maximumLayoutSize(Container parent)
          {
      return minimumLayoutSize(parent);
          }


         public void layoutContainer(Container component)
          {
           int noOfComponents = components.size();
           Component c;
           Dimension d;
           Dimension d1;

           Insets insets = component.getInsets();

           for (int i = 0; i < noOfComponents; i ++)
           {
             c = (Component) components.elementAt(i);
                   d = (Dimension) dimensions.elementAt(i);
             d1 = c.getPreferredSize();
             c.setBounds(d.width + insets.left, d.height + insets.top, d1.width, d1.height);
            }
          }

      public float getLayoutAlignmentX(Container parent)
      {
      return 0.5f;

      }
      public float getLayoutAlignmentY(Container parent)
      {
      return 0.5f;

      }

      public void invalidateLayout(Container parent)
      {
      }

           /*--------------------------------STANDARD METHODS----------------------*/

         public void setWidthAndHeight(Dimension widthAndHeight)
          {
           width = widthAndHeight.width;
           height = widthAndHeight.height;
          }

         public void setWidthAndHeight(int aWidth, int aHeight)
          {
           width = aWidth;
           height = aHeight;
          }

      }


      company - BLCMP Library Services Ltd , email - ###@###.###
      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: