Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4223515

Add subimage capability to ImageIcon to allow use of image sheets

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.1
    • client-libs
    • Fix Understood
    • generic
    • solaris_10

      From: "S.E. Morris" <###@###.###>
      To: ###@###.###
      Subject: Idea for ImageIcon.
      Cc: "S.E. Morris" <###@###.###>
      Date: Wed, 24 Mar 1999 13:57:53 +0000 (GMT)

      Swing gives you the ability to add images to many of it's GUI
      components via the ImageIcon class - however there is a rather
      annoying limitation of ImageIcon which I'd like to prepose a fix
      to.

      ImageIcon's (as far as I can tell) can only be created from
      complete 'Image's - ie: it uses the whole of the image you give
      it as the icon. When loading images across a network -
      particularly something like the Internet - fetching multiple
      files is tedious and slow. The overhead alone in creating,
      for example, a separate HTTP request to a web server for each
      image can be quite large. Even having multiple image files
      in a non-networked application can be too much hassle sometimes.

      Some of us more enterprising souls have therefore taken to
      blocking multiple icon-style images into a single file (I think
      this is commonly known as an 'image sheet'!). An example of what
      I mean is this file, intended for use as button icons for an
      e-mail applet:
      http://www.csc.liv.ac.uk/~fish/java/MerseyMail/icons.gif

      (Don't laugh - I'm a programmer not an artist!!)

      The above icons are used in my own pre-Swing icon buttons
      (subclassed from Canvas) which allowed you to specify a x and y
      offset into the image as well as a width and height for the area of
      the Image that the button icon would use. For a real example see:
      http://anfield.merseyworld.com/chat/detach.html
      http://anfield.merseyworld.com/chat/icons2.gif

      When I use ImageIcon I have to extract an Image from my 'sheet'
      before passing it in to ImageIcon. This is a lot of hassle and
      creates a separate Image object for each ImageIcon to hold.
      It would be nice if I could pass the same Image into each
      ImageIcon but with a different x/y offset and width/height.
      Less hassle and probably slightly more memory efficient.

      Perhaps a new constructor type:

      ImageIcon(Image i,int x,int y,int w,int h)

      ... might do the trick? And/or just add a new method, something
      along the lines of:

      public void setIconDisplayArea(int x,int y,int w,int h)


      Anyway, that's my 2 pence worth. You're probably going to
      tell me there's some blatantly obvious way to do the above that
      I have complete missed, but anyway thanks for listening...

      -FISH- ><>

      (S.E. Morris - lead Java bod at Connect, the University of
      Liverpool's Internet R+D Centre)

            Unassigned Unassigned
            amfowler Anne Fowler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: