• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help Graphic is not displaying!

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jcomponent for which I have overwritten the paintComponent() method. In this method, I am drawing images in a variety of places. This jcomponent is also an observer to another object that is deciding where images should be plotted.

In my update() method, I have verified that I am catching the event that is saying a new image has been plotted. I have also verified that I am calling revalidate(), repaint() and I've even tried updateUI() and lots of other things. However, my paintComponent() method is NOT being called and this is a problem.

One other thing I have tried is to call paintComponent() directly - paintComponent(getGraphics()). This calls my paintComponent() method and I have verified that it is calling drawImage() at the appropriate location. However, the image that is supposed to be being drawn is STILL NOT showing up.

Any ideas??? I'm at a total loss...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some possibilities:
How are you loading the images? ImageIcon and ImageIO will block execution until the image is full–loaded. If you are using an older method such as 'getImage' in Toolkit you may have to use a MediaTracker (api has example of use) to get it fully–loaded before moving on to the rendering. One way to check the image is to ask for its width and height. You'll get a zero if it isn't fully–loaded.

Another possibility is corrupted image files or images not properly saved.

Another is path trouble. Some methods don't report that they couldn't find an image at the path they were given. ImageIO does tell you.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using ImageIcon and my icon is very small - 160 bytes for 7x7 pixels. I shouldn't have a path problem because I am using the same ImageIcon object in other places and the image is being displayed.

Thanks for the suggestions!!!
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the image component visible? Try setting a border or background or painting a red oval on it. If it has no components or size hints you may have to set a preferred size for it so the parent container knows how to show it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic