Scrollbars get obscurred when painting image; how to fix

N

news.rcn.com

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.
 
K

Knute Johnson

news.rcn.com said:
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.

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().
 
N

news.rcn.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top