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

JScrollPane within GridBagLayout does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.2.2
    • 1.1.6
    • client-libs
    • 1.2.2
    • x86
    • windows_nt



      Name: diC59631 Date: 10/01/98


      This bug applies to Swing 1.1beta only.

      1. Steps to reproduce
      ---------------------
      The provided sample program creates a JScrollPane,
      adds some contents to it, and places it into
      a GridBagLayout.
      It then opens a JFrame which is too small for
      the contents to display.

      - With Swing 1.0.3 this forces the JScrollPane
      to show the ScrollBars.
      When you resize the JFrame, the visible amount
      of the contents changes gradually. The ScrollBars
      will disappear when the frame gets large
      enough to show the whole contents.
      So everything works fine here.

      - With Swing 1.1beta instead, you will see only
      a tiny rectangle in the center of the frame.
      The contents is not visible!
      Resizing the frame does never bring up any
      ScrollBars: You will see the rectangle when
      the frame is small ... and you will she the whole
      contents when the frame is large enough.

      2. The source code
      ------------------
      import com.sun.java.swing.*;
      import java.awt.*;

      import com.sun.java.swing.*;
      import com.sun.java.swing.table.*;

      public class JScrollPaneBug
      extends JPanel
      {
      /**
      This method creates a JScrollPane,
      adds some contents to it and places
      it into the GridBagLayout.
      */
      public JScrollPaneBug()
      {
      setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = 0;
      c.weightx = 1.0;
      c.weighty = 1.0;
      JScrollPane scrollPane = new JScrollPane(createSomeContents());

      add(scrollPane,c);
      }
      /**
      This method is not part of the problem.
      It's just creating some contents for the JScrollPane.
      */
      public JComponent createSomeContents()
      {
      JPanel p = new JPanel(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = 0;
      p.add(new JLabel("label one"),c);

      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = 0;
      p.add(new JTextField(30),c);

      c.gridx = 0;
      c.gridy = 1;
      p.add(new JLabel("label two"),c);

      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = 1;
      c.weightx = 1.0;
      c.weighty = 1.0;
      p.add(new JTextField(30),c);

      c.gridx = 0;
      c.gridy = 2;
      p.add(new JLabel("label three"),c);

      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = 2;
      c.weightx = 1.0;
      c.weighty = 1.0;
      p.add(new JTextField(30),c);

      return p;
      }
      /**
      Creates a frame that is too small for the
      contents we want to display. Thus forcing
      the ScrollBars of the JScrollPane to be
      displayed.
      */
      public static void main(String[] args)
      {
      JFrame f = new JFrame();
      f.getContentPane().add(new JScrollPaneBug());
      f.setSize(300,300);
      f.setVisible(true);
      }
      }
      (Review ID: 36789)
      ======================================================================

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: