Netbeans debug shows Image object has height/width property??
Hello,
I've been playing around with http://docs.oracle.com/javase/tutori...umbleItem.java.
While debugging, I noticed that netbeans shows that the image data (returned from Toolkit.getDefaultToolkit().createImage(buf)) contains a width and height property. I noticed from Image (Java 2 Platform SE v1.4.2) that Image doesn't have a height and width property. Also, the debug session showed that the height and width property were both -1.
Am I missing something?
Stephen
Re: Netbeans debug shows Image object has height/width property??
Image is an abstract class, and so the createImage must make an object from a concrete subclass of Image, possibly BufferedImage which does contain height and width properties. As for the -1, I can't comment on that as I don't have your code.
Re: Netbeans debug shows Image object has height/width property??
An Image returned from a (AWT) Toolkit method is of type sun.awt.image.ToolkitImage.
The documentation for Image#getWidth/Height(ImageObserver) explains when the width/height returned will be -1
Quote:
If the width/height is not yet known, this method returns -1 and the specified ImageObserver object is notified later.
One major difference in the two classes is that ToolkitImage supports animation, while BufferedImage does not.
There's more about the concrete Image subclasses in the documentation for flush().
db
Re: Netbeans debug shows Image object has height/width property??
I didn't see any height or width property specified in BufferedImage (Java Platform SE 6), although I noticed the constructor takes a height and width. Is there some web page that list all the properties?
The code is located at http://docs.oracle.com/javase/tutori...umbleItem.java. I did modifiy the code at line 309 with the following:
Image a = Toolkit.getDefaultToolkit().createImage(buf);
return new ImageIcon(a);
so I can see what is returned from Toolkit.getDefaultToolkit().createImage(buf).
Re: Netbeans debug shows Image object has height/width property??
For that specific program, would you have any idea why the height and width would be -1?
Re: Netbeans debug shows Image object has height/width property??
Quote:
I didn't see any height or width property specified in BufferedImage
You don't see the methods getHeight() and getWidth()?
Quote:
For that specific program, would you have any idea why the height and width would be -1?
I already quoted the relevant API in this thread. Read the responses.
db
Re: Netbeans debug shows Image object has height/width property??
Quote:
Originally Posted by
DarrylBurke
You don't see the methods getHeight() and getWidth()?
I already quoted the relevant API in this thread. Read the responses.
db
I did read the response and I didn't realise I had to call the getHeight/getWidth property to set the Height and width respectively. I had thought that they were set automatically and that your reference to those two methods meant for some reason that the Height and Width were unknown.
I called the two methods and was able to get the Height and width.
It would be nice if the Java API listed all of the properties.
Re: Netbeans debug shows Image object has height/width property??
The term "property" is used a bit loosely. It can mean "some aspect of state with corresponding java bean naming conventions for its accessors". That is, if it has getHeight()/setHeight() then it has a height property. Or it can refer specifically to an (instance?) member variable or field. Oracle's Tutorial and the JLS favour "field" (as do I) with field+method+...=member
I don't know what fubarable meant, but there is no height field in BufferedImage. Instead there's a writable raster field which contains this state. ToolkitImage - which is what you've got - does have a height field, although it's private.
See, eg, docjar.com.
Re: Netbeans debug shows Image object has height/width property??
pbrockway2,
Thanks. I didn't no about docjar.com.
Stephen
Re: Netbeans debug shows Image object has height/width property??
You're welcome. A lot of source code comes with the SDK, but docjar is handy and comprehensive.
Re: Netbeans debug shows Image object has height/width property??
Quote:
Originally Posted by
pbrockway2
Tif it has getHeight()/setHeight() then it has a height property.
Just for completeness, if it has getHeight() but no setHeight(...) then it has a height property which is read-only.
db