Class ImageListPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ImageListPanel extends JPanel
A scrollable panel that can show a list of images, each represented by a thumbnail and an optional label to describe the image. The user can optionally add new images to the list, remove them from the list, or double-click an image to view it in a popup window.

NOTE: this component will grow horizontally without ever wrapping! The intention is that it will be added to a JScrollPane to prevent the component from taking up an unreasonable amount of space. It contains mouse listeners that will allow clicking and dragging on any image panel to scroll left/right within the list, if the ImageListPanel is added to a JScrollPane container.

Since:
swing-extras 2.5
Author:
scorbo2
See Also:
  • Field Details

  • Constructor Details

    • ImageListPanel

      public ImageListPanel(Window ownerWindow)
      Creates a new, empty ImageListPanel.
  • Method Details

    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Determines whether image addition and removal operations are permitted, and also whether drag and drop from the file system is allowed.
    • isReadOnly

      public boolean isReadOnly()
      Returns whether this panel allows image addition and removal operations, and also whether drag and drop from the file system is allowed.
    • getMaxListSize

      public int getMaxListSize()
      Returns the configured maximum image count that this panel will allow. Addition attempts beyond this count are discarded.
    • setMaxListSize

      public void setMaxListSize(int max)
      Puts a limit on the number of images that this panel will allow. By default, this is Integer.MAX_VALUE.

      WARNING: Passing a value that is less than the number of images currently held in this panel will cause all images at indexes higher than this count to be dropped.

    • setThumbnailSize

      public void setThumbnailSize(int newSize)
      Sets a new pixel size for our image thumbnails. Note that our thumbnails will always be scaled proportionally to fit a square bounding area, so the given pixel value represents both the desired width and the height of each thumbnail. This method will force a reload of the panel to force all current images to redisplay at the new thumb size.
    • addImage

      public void addImage(BufferedImage image)
      Adds a new image to the list. The list displays images in the order that they are added! Re-ordering the list dynamically is not yet possible.
    • addImage

      public void addImage(BufferedImage thumbnail, ImageIcon imageIcon)
      Adds a new animated gif to the list. The list displays images in the order that they are added! Re-ordering the list dynamically is not yet possible.
    • getImageCount

      public int getImageCount()
      Reports how many images are in the current list.
    • setBackground

      public void setBackground(Color color)
      We override this so that we can update any child ImagePanels to have the same background color.
      Overrides:
      setBackground in class JComponent
      Parameters:
      color - the desired background Color
    • clear

      public void clear()
      Removes all images.
    • getImageAt

      public Object getImageAt(int index)
      Returns the image at the given index, or null if the given index is invalid. The return will be EITHER a BufferedImage for static image formats like jpeg or png, OR an ImageIcon if the image was an animated GIF. Caller has to check.
    • getThumbnailAt

      public BufferedImage getThumbnailAt(int index)
      Returns the scaled thumbnail at the given index, or null if the given index is invalid. If the image at the given index is an animated GIF, this will give you the scaled static thumbnail which was based on the first frame of the animation.
    • removeImage

      public void removeImage(int index)
      Remove an image by index. If the given index is invalid, this call does nothing.
    • getOwnerWindow

      public Window getOwnerWindow()
      Returns the owner Window that will be used as a parent for the popup preview window (null is acceptable).
    • setOwnerWindow

      public void setOwnerWindow(Window ownerWindow)
      Sets the owner Window that will be used as a parent for the popup preview window (null is acceptable).
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Callers can subscribe to receive ChangeEvents when images are added or removed to or from this panel.
    • removeChangeListener

      public void removeChangeListener(ChangeListener listener)
    • enableDragAndDrop

      public void enableDragAndDrop()
      Enables drag-and-drop of image files from the filesystem onto this panel.