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.
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.
posted 14 years ago
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!!!
posted 14 years ago
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