Results 1 to 11 of 11
- 04-08-2012, 10:55 AM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 211
- Rep Power
- 0
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.
- 04-08-2012, 04:44 PM #3
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
If the width/height is not yet known, this method returns -1 and the specified ImageObserver object is notified later.
There's more about the concrete Image subclasses in the documentation for flush().
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-09-2012, 02:29 AM #4
Senior Member
- Join Date
- Apr 2012
- Posts
- 211
- Rep Power
- 0
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).Last edited by shall; 04-09-2012 at 02:33 AM.
- 04-09-2012, 02:35 AM #5
Senior Member
- Join Date
- Apr 2012
- Posts
- 211
- Rep Power
- 0
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?
- 04-09-2012, 05:38 AM #6
Re: Netbeans debug shows Image object has height/width property??
I didn't see any height or width property specified in BufferedImage
For that specific program, would you have any idea why the height and width would be -1?
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 04-09-2012, 07:59 AM #7
Senior Member
- Join Date
- Apr 2012
- Posts
- 211
- Rep Power
- 0
Re: Netbeans debug shows Image object has height/width property??
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.
- 04-09-2012, 08:43 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 18
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.
- 04-09-2012, 09:22 AM #9
Senior Member
- Join Date
- Apr 2012
- Posts
- 211
- Rep Power
- 0
Re: Netbeans debug shows Image object has height/width property??
pbrockway2,
Thanks. I didn't no about docjar.com.
Stephen
- 04-09-2012, 09:57 AM #10
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 18
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.
- 04-09-2012, 11:57 AM #11
Similar Threads
-
The dialog initiates with height=0 and width=0
By krimen_sp in forum New To JavaReplies: 8Last Post: 01-24-2011, 08:45 PM -
Width (-1) and height (-1) cannot be <= 0
By LovJava in forum AWT / SwingReplies: 5Last Post: 04-24-2010, 01:16 AM -
I want set HEIGHT, WIDTH for Button
By manhtungtnk28@gmail.com in forum AWT / SwingReplies: 3Last Post: 11-16-2009, 08:26 AM -
Using setBounds (x.y,width,height) constructor
By hitmen in forum AWT / SwingReplies: 3Last Post: 03-06-2009, 01:12 PM -
Get Image Height and Width
By neeraj.singh in forum AWT / SwingReplies: 10Last Post: 02-18-2009, 02:09 PM
Bookmarks