This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Help Graphic is not displaying!  RSS feed

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!