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

ScrollPane reserves area for scroll bars but doesn't display them

    XMLWordPrintable

Details

    • b01
    • x86
    • windows_nt
    • Not verified

    Backports

      Description



        Name: chT40241 Date: 03/05/98



        If the ScrollPane is slightly larger than its contents and
        SCROLLBARS_AS_NEEDED is set, the ScrollPane "reserves" the area
        where scroll bars would go, but it doesn't display them. This
        area then is painted the background color of the ScrollPane
        indicating that the ScrollPane is occupying that area, not
        the child of the ScrollPane.

        This is a bad problem for a program that I am writing. The
        program allows the user to lay out java components in a work
        area that is actually a ScrollPane. If the user places a
        component too close to the bottom or right edges of the area,
        this bug shows up.

        **** Start ChoiceList.java ******
        import java.awt.*;
        import java.awt.event.*;

        // Shows ScrollPane bug where ScrollPane "reserves" area for the scroll bars
        // but doesn't put them on the screen. This occurs when the ScrollPane is
        // slightly only larger than its contents and has SCROLLBARS_AS_NEEDED set.
        // This example should show up on screen such that there are red rectangles to
        // the right and below the buttons. If this is not the case, resize the frame
        // so that it is only slightly larger (10 to 20 pixels wider and taller) than
        // the buttons it contains. This bug is very frustrating when using ScrollPane
        // to make custom list boxes and component layout areas.
        // JDK 1.1.6I, WinNT 4.0 SP3
        public class ChoiceList {
            public static void main(String[] args) {
                Frame f = new Frame("ChoiceList test");
                f.setLayout(new java.awt.BorderLayout());

                ScrollPane c = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
                c.setBackground(Color.red);
                f.add(c, "Center");

                Panel panel = new Panel(new java.awt.FlowLayout());
                c.add(panel);
                panel.setBackground(Color.white);

                Button b1, b2, b3;
                panel.add(b1 = new Button("Button1"));
                panel.add(b2 = new Button("Button2"));
                panel.add(b3 = new Button("Button3"));

                f.pack();

                Dimension size = new Dimension();
                size.width += b1.getPreferredSize().width;
                size.height += b1.getPreferredSize().height;
                size.width += b2.getPreferredSize().width;
                size.height += b2.getPreferredSize().height;
                size.width += b3.getPreferredSize().width;
                size.height += b3.getPreferredSize().height;

                // set size to show where ScrollPane will reserve room for the scroll
                // bars, but not actually put them on screen; this "reserved" area will
                // show up as red since it is actually the ScrollPane showing in those
                // areas; if it doesn't show up this way, resize the frame to be only
                // slightly larger than the buttons
                f.setSize(size.width + 45, size.height + 20);

                f.setVisible(true);
            }
        }
        **** End ChoiceList.java ******

        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                rkhansunw Robi Khan (Inactive)
                chickeysunw Chuck Hickey (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: