Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drawString working, drawImage isn't

Status
Not open for further replies.

brownie124

Programmer
Sep 19, 2002
61
US
I have written a fairly complex package that is a custom component. I am using 1.2. I have overridden the paint() method in a class. It calls a method of another class and passes on the Graphics parameter passed into the paint method. Drawing text and lines works fine. However, I go to draw an image and I am having problems. The image will not appear but in one area of the component. Even at that it doesn't appear the first time (I click in that area and it is supposed to appear). I have to click again for it to appear.

Anyway, is this enough for anybody to go on. There is so much code that it would be too difficult to figure out and put in here. Bottom line is, in what instances will something like g.drawString() work, but g.drawImage won't?

Thanks,
- Michael
 
>> n what instances will something like g.drawString()
>> work, but g.drawImage won't?

One instance is when the Image has not finished loading.

-pete
 
See the following thread for an example of "g.drawImage()" and an "ImageLoader" that will wait until the Image is fully loaded :
thread137-560762
PS : If you change JFrame to Frame and Color.CYAN to Color.cyan the example will work without using Swing.
 
Thanks for the responses! That addressed the issue with the image not appearing upon the first click. I would not have suspected that because it is such a small image.

However, I can still only draw the image in the one spot. I click in another area and it won't draw. I swap drawImage(img, x, y, null) for drawString("x", x , y) and the x appears.

- Michael
 
The code in Thread137-560762 works for me (jdk1.3.1 and jdk1.4.2). I can put the image anywhere on the screen. So you must be doing something different. Although jdk1.2 is rather old. Does the code in the above mentioned thread work for you ? If yes, try to post some code. If no, then let me know, then I'll download jdk1.2 and retry my code.
 
Sorry, I didn't make myself clear before. Your code worked fine. It was my code that I changed and the delay in the appearance of the one image was fixed once I used the MediaTracker class. It was the other problem that was still there. However.....I fixed it!!!

I was doing a fillRect() before doing my drawImage() for only the one that was painting; I was not doing it for the other rows of data.

Thanks so much for your help.

- Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top