Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Scrollbars get obscurred when painting image; how to fix

Thread view: 
news.rcn.com - 16 Aug 2007 17:37 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
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().


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.