Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2027

Re: Problem with loaded i

From "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this>
Subject Re: Problem with loaded i
Message-ID <slrnf9d0d9.6cj.aggedor@earl-grey.cloud9.net> (permalink)
Newsgroups comp.lang.java.gui
References <f75icg$6r8$1@newsreader2.utanet.at>
Date 2011-04-27 15:36 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
On 2007-07-12, Daniel Kraft <d@domob.eu> wrote:
> Hi all,
>
> I've run into a rather strange problem, at least for me.  I've got an 
> AWT Frame containing a Canvas at the center of a BorderLayout which an 
> Image is painted on.
>
> This Canvas returns the Image's size as preferred size, so on pack()-ing 
> the Frame the Image exactly fits in to the Canvas.  This works so far.
>
> However, during runtime the image gets changed, thus also the preferred 
> size changes (becomes larger).  After this, I call pack() on the Frame 
> again, and it resizes accordingly.  But in spite, the image is drawn 
> only in the region of its old size, i.e., the new bigger part is gray 
> and the image clipped (I'm calling repaint() after the pack() but that 
> seems not to help).
>
> But if I force a repaint by hiding and showing the window through my 
> window manager, the image gets drawn completely.
>
> I really have no clue about what the problem could be -- my only 
> suspicion is this one:  I use a MediaTracker to load the image so I can 
> query for its size; this MediaTracker is initialized with my Canvas as 
> ImageObserver when it still has its old size.  Can this cause any 
> problem, as only that part of the image is loaded or something like 
> that?  It sounds strange to me, but is really the only possible reason 
> coming to my mind...

You should also be suspicious about what is done differently by the
update and paint methods of the extension of Canvas.  You are likely
seeing different redrawing results from pack() and hiding-and-showing
because one ends up invoking update while the other ends up invoking
paint.  See

http://java.sun.com/products/jfc/tsc/articles/painting/index.html#awt

for a description of "Painting in the AWT".

> I'm using JDK 1.5.0_06 on GNU/Linux.  If anyone is interested in the 
> sources, they can be browsed at
> http://minigolf.svn.sourceforge.net/viewvc/minigolf/trunk/src/
> The Canvas-component talked about is
> net.sourceforge.minigolf.visualizer.Visualizer

Based on taking a look at the source

- the update method draws to an Image object (the variable offscreen)
  and draws the image to the Graphics argument of the update method

- the Image object is created only once, although you change the
  size of the image to be drawn the update method draws to the size
  of the original image

You should set the variable offscreen to null when the size of the
images changes so the update method will create a new one with the
correct size.  Because the update method is the only place where
the variable offscreen is used, you may want to eliminate it and
the definition of the update method in your extension of Canvas.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Problem with loaded image "Daniel Kraft" <daniel.kraft@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
  Re: Problem with loaded i "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
  Re: Problem with loaded i "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
    Re: Problem with loaded i "Daniel Kraft" <daniel.kraft@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
      Re: Problem with loaded i "A. Bolmarcich" <a..bolmarcich@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000
        Re: Problem with loaded i "Daniel Kraft" <daniel.kraft@THRWHITE.remove-dii-this> - 2011-04-27 15:36 +0000

csiph-web