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

GridBagLayout fails to map container according to specification

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • x86
    • solaris_2.6



      Name: rm29839 Date: 04/06/98


      (This bug was reported previously against
      JDK 1.2beta2 and I was informed that it had
      already been fixed in JDK 1.2beta3. However,
      I found the bug to still exist in beta3.)
      Here is the test case the demonstates a bug
      in the GridBagLayout:
      ---------------------------------------------
      /*
       * This class illustrates a bug in the AWT GridBagLayout class.
       *
       * It should display a frame that looks like this:
       *
       * 0 8 10
       * 0 +----------------------------+-----------+
       * | Upper Left | |
       * 1 +----------------------------+ |
       * | | |
       * | | |
       * | | Right |
       * | | |
       * | | |
       * | | |
       * | | |
       * 5 +----------------------------+-----------+
       * | |
       * | Bottom |
       * | |
       * 7 +----------------------------------------+
       *
       * Instead, it thinks that the "Right" frame should occupy the
       * entire portion above "Bottom"
       */
      class B {
          static void addit(GridBagLayout grid,
                              Container pane, String msg, GridBagConstraints cons){
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.setBorder(new EtchedBorder());
              panel.add("Center",new JButton(msg));
              grid.setConstraints(panel,cons);
              pane.add(panel);
              }
          public static void main(String args[]){
              System.out.println("Java Version " + System.getProperty("java.version"));
              JFrame frame = new JFrame();
              Container pane = frame.getContentPane();
              GridBagLayout grid = new GridBagLayout();
              pane.setLayout(grid);
              GridBagConstraints cons = new GridBagConstraints();

              cons.gridx = 0;
              cons.gridy = 0;
              cons.gridheight = 1;
              cons.gridwidth = GridBagConstraints.RELATIVE;
              cons.fill = GridBagConstraints.HORIZONTAL;
              cons.weightx = 1;
              cons.weighty = 1;
              cons.anchor = GridBagConstraints.NORTH;
              addit(grid,pane,"Upper Left",cons);

              cons.anchor = GridBagConstraints.SOUTH;
              cons.gridx = 0;
              cons.gridy = 5;
              cons.gridwidth = GridBagConstraints.REMAINDER;
              cons.gridheight=2;
              cons.fill = GridBagConstraints.BOTH;
              addit(grid,pane,"Bottom",cons);

              cons.gridx = 8;
              cons.gridy = 0;
              cons.gridwidth = 2;
              cons.gridheight = GridBagConstraints.RELATIVE;
              cons.anchor = GridBagConstraints.EAST;
              addit(grid,pane,"Right",cons);

              frame.pack();
              frame.setSize(500,500);
              frame.setVisible(true);
              }

      }
      (Review ID: 27113)
      ======================================================================

            lbunnisunw Lara Bunni (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: