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.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2314 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2003-03-22 01:56:09 +00:00
parent 712d3f8ab5
commit f6c16e6faf
@@ -1,9 +1,10 @@
//
// $Id: SafeScrollPane.java,v 1.6 2002/11/05 21:03:31 mdb Exp $
// $Id: SafeScrollPane.java,v 1.7 2003/03/22 01:56:09 mdb Exp $
package com.threerings.media;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JComponent;
@@ -24,6 +25,29 @@ public class SafeScrollPane extends JScrollPane
super(view);
}
public SafeScrollPane (Component view, int owidth, int oheight)
{
super(view);
if (owidth != 0 || oheight != 0) {
_override = new Dimension(owidth, oheight);
}
}
// documentation inherited
public Dimension getPreferredSize ()
{
Dimension d = super.getPreferredSize();
if (_override != null) {
if (_override.width != 0) {
d.width = _override.width;
}
if (_override.height != 0) {
d.height = _override.height;
}
}
return d;
}
protected JViewport createViewport ()
{
JViewport vp = new JViewport() {
@@ -42,4 +66,6 @@ public class SafeScrollPane extends JScrollPane
vp.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
return vp;
}
protected Dimension _override;
}