//
// $Id: SafeScrollPane.java,v 1.6 2002/11/05 21:03:31 mdb Exp $

package com.threerings.media;

import java.awt.Component;
import java.awt.Point;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JViewport;

/**
 * A scroll pane that is safe to use in frame managed views.
 */
public class SafeScrollPane extends JScrollPane
{
    public SafeScrollPane ()
    {
    }

    public SafeScrollPane (Component view)
    {
        super(view);
    }

    protected JViewport createViewport ()
    {
        JViewport vp = new JViewport() {
            public void setViewPosition (Point p) {
                super.setViewPosition(p);
                // simple scroll mode results in setViewPosition causing
                // our view to become invalid, but nothing ever happens to
                // queue up a revalidate for said view, so we have to do
                // it here
                Component c = getView();
                if (c instanceof JComponent) {
                    ((JComponent)c).revalidate();
                }
            }
        };
        vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
        return vp;
    }
}

@@ -32,29 +32,29 @@
 v 1.
-6
+7
  200
-2/11/05 21:03:31
+3/03/22 01:56:09
  mdb
@@ -111,32 +111,59 @@
 .awt.Component;%0A
+import java.awt.Dimension;%0A
 import java.awt.
@@ -498,24 +498,626 @@
 ew);%0A    %7D%0A%0A
+    public SafeScrollPane (Component view, int owidth, int oheight)%0A    %7B%0A        super(view);%0A        if (owidth != 0 %7C%7C oheight != 0) %7B%0A            _override = new Dimension(owidth, oheight);%0A        %7D%0A    %7D%0A%0A    // documentation inherited%0A    public Dimension getPreferredSize ()%0A    %7B%0A        Dimension d = super.getPreferredSize();%0A        if (_override != null) %7B%0A            if (_override.width != 0) %7B%0A                d.width = _override.width;%0A            %7D%0A            if (_override.height != 0) %7B%0A                d.height = _override.height;%0A            %7D%0A        %7D%0A        return d;%0A    %7D%0A%0A
     protecte
@@ -1791,16 +1791,52 @@
 urn vp;%0A
-
     %7D
+%0A%0A    protected Dimension _override;
 %0A%7D%0A

Allow preferred width or height to be overridden since it seems that JScrollPane will happily return some insane value when it's wrapping an empty JList.