Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Netbeans debug shows Image object has height/width property??

  1. #1
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default 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.
    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
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default 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 01:33 AM.

  5. #5
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default 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?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Netbeans debug shows Image object has height/width property??

    I didn't see any height or width property specified in BufferedImage
    You don't see the methods getHeight() and getWidth()?

    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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Netbeans debug shows Image object has height/width property??

    Quote Originally Posted by DarrylBurke View Post
    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.

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.

  9. #9
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Netbeans debug shows Image object has height/width property??

    pbrockway2,

    Thanks. I didn't no about docjar.com.

    Stephen

  10. #10
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Netbeans debug shows Image object has height/width property??

    Quote Originally Posted by pbrockway2 View Post
    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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. The dialog initiates with height=0 and width=0
    By krimen_sp in forum New To Java
    Replies: 8
    Last Post: 01-24-2011, 07:45 PM
  2. Width (-1) and height (-1) cannot be <= 0
    By LovJava in forum AWT / Swing
    Replies: 5
    Last Post: 04-24-2010, 12:16 AM
  3. I want set HEIGHT, WIDTH for Button
    By manhtungtnk28@gmail.com in forum AWT / Swing
    Replies: 3
    Last Post: 11-16-2009, 07:26 AM
  4. Using setBounds (x.y,width,height) constructor
    By hitmen in forum AWT / Swing
    Replies: 3
    Last Post: 03-06-2009, 12:12 PM
  5. Get Image Height and Width
    By neeraj.singh in forum AWT / Swing
    Replies: 10
    Last Post: 02-18-2009, 01:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •