I am trying to display an image in a JScrollpane. When I reduce the size
of the application window (by dragging the corner) so that the scrollbars
appear, the image is painted over the scrollbars and obscures them.
A button of the same size as the Canvas doing the painting does not show
the same behavior.
If I have the paint() method just draw a line or even do nothing, the same
problem occurs.
Is there some clipping region that should be applied when painting?
(Graphics.getClipBounds() doesn't seem to be the right area.)
Should the Canvas be resized before painting?
Can anybody help me solve this problem? A lot of Goggling and reading of
the Java docs and Java Tutorial hasn't helped.
I appreciate any help or suggestions you might provide.
Thanks a lot,
Jim Cant
Here's the window setup:
JFrame (app top level window.
JScrollPane
JPanel ('main' panel passed to JScrollPane constructor )
JPanel
JButton
JPanel
MyCanvas (extended from Canvas, paint overidden calls
" graphics.drawImage( theImage, 0, 0,
null )").;
I have a simple test program demonstrating this problem.
Knute Johnson - 16 Aug 2007 21:27 GMT
> I am trying to display an image in a JScrollpane. When I reduce the size
> of the application window (by dragging the corner) so that the scrollbars
[quoted text clipped - 32 lines]
>
> I have a simple test program demonstrating this problem.
You are mixing AWT and Swing components (heavyweight/lightweight). You
are going to have painting problems if you do that. Just change your
Canvas to a JComponent or JPanel. And remember to use paintComponent()
instead of paint().

Signature
Knute Johnson
email s/nospam/knute/
news.rcn.com - 16 Aug 2007 22:46 GMT
Knute,
Thanks!! You are quite correct, it's the heavyweight Canvas that was the
problem. I conclude that the 'root' of painting functionality that is in
the heavyweight Canvas got transplanted to the JComponent of the lightweight
species (making it available to subclasses).
Thanks again; I spent a day on this problem and it's great to have it solved
jim cant
p.s. For other non-gurus, I found this (after the fact) which is pretty
helpful: http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html
>> I am trying to display an image in a JScrollpane. When I reduce the
>> size of the application window (by dragging the corner) so that the
[quoted text clipped - 39 lines]
> Canvas to a JComponent or JPanel. And remember to use paintComponent()
> instead of paint().