
Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
>>// Begin SSCCE
[...]
>>// End SSCCE
>
[quoted text clipped - 4 lines]
> code that displays the problem, and if so, how do you get it
> to compile? Alternately - what is the actual code?
OK, Andrew, you are right.
My 2 methods getScrollableTracksViewportWidth and
getScrollableTracksViewportHeight slipped by
during copy/paste in my first post. :-(
> BTW - it is difficult to tell if anything is happening unless
> you paint a gradient on the image or add some println's..
Well, at least I could see the scrollbar jumping (or not jumping,
in the 1.5 case).
Anyway: I added a constructor drawing some text onto the image.
So here is the new one:
// Begin SSCCE
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class ImageComponent extends JComponent implements Scrollable
{
public static void main(String args[])
{
JFrame frame = new JFrame("Scroll Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane scrollPane = new JScrollPane(new ImageComponent());
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
private BufferedImage image = // a meaningless large image
new BufferedImage(850, 1100, BufferedImage.TYPE_BYTE_GRAY);
public ImageComponent()
{
Graphics2D g = image.createGraphics();
for (int i = 1; i < 200; i++)
g.drawString("Line " + i + ": bla bla bla", 0, i * 12);
}
public Dimension getPreferredSize()
{
return new Dimension(image.getWidth(), image.getHeight());
}
protected void paintComponent(Graphics g)
{
g.drawImage(image, 0, 0, this);
}
// Implementation of Scrollable interface:
public Dimension getPreferredScrollableViewportSize()
{
return new Dimension(Math.min(image.getWidth(), 500),
Math.min(image.getHeight(), 500));
}
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation, int direction)
{
return getScrollableBlockIncrement(visibleRect, orientation,
direction) / 10;
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction)
{
switch (orientation)
{
case SwingConstants.HORIZONTAL: return visibleRect.width;
case SwingConstants.VERTICAL: return visibleRect.height;
default: throw new IllegalArgumentException();
}
}
public boolean getScrollableTracksViewportHeight()
{
return false;
}
public boolean getScrollableTracksViewportWidth()
{
return false;
}
}
// End SSCCE

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Andrew Thompson - 15 Jun 2005 17:23 GMT
...
>> BTW - it is difficult to tell if anything is happening unless
>> you paint a gradient on the image or add some println's..
> Well, at least I could see the scrollbar jumping (or not jumping,
> in the 1.5 case).
> Anyway: I added a constructor drawing some text onto the image.
I added a printlns to each method..
> So here is the new one:
I can confirm that it scrolls using Java 1.4.0, but not 1.5.0_03.
The printlns indicated that getScrollableUnitIncrement &
getScrollableBlockIncrement were being called by Java 1.4,
but not 1.5.

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane