Class JImageComponent

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class JImageComponent extends JComponent
Image component allowing image to be presented at different zoom levels Intended to installed inside a JZoomScrollPane. Paints image centered and respecting aspect ratio (Attempt to handle layout by parent component failed - caused jerky zooming) Use getImageBounds() to get bounds of image relative to this component Supports quick presentation of low-res image and lazy-loading of full size image via setImageProvider method
Since:
16.3
See Also:
  • Field Details

    • workingProperty

      public final javafx.beans.property.BooleanProperty workingProperty
      Tells whether this component is loading images in the background. Bind to JProgressSpinner via JProgessSpinner.setModel()
  • Constructor Details

    • JImageComponent

      public JImageComponent()
      Create empty image component
    • JImageComponent

      public JImageComponent(BufferedImage image)
  • Method Details

    • getImage

      public Image getImage()
    • setImage

      public void setImage(BufferedImage image)
      Parameters:
      image - to set. Pass null to clear
    • setImage

      public void setImage(Image image, Dimension fullSize)
      Set usually smaller image, and inform component of lazy-loaded full sized image's dimensions
      Parameters:
      image -
      fullSize -
    • setImageAsync

      public Future setImageAsync(JImageComponent.ImageProvider imageProvider, Dimension fullSize)
      Same as setImage(Image image, Dimension fullSize) but asynchronous
    • setImageProvider

      public void setImageProvider(JImageComponent.ImageProvider provider)
      Install provider for larger (normally uncached) images, loaded as user zooms in (Loaded in background thread so is allowed to take some time)
      Parameters:
      provider -
      Since:
      16.3
    • scheduleReload

      public void scheduleReload(Dimension newDim)
      Trigger background reloading of current image Needs image provider to be installed
      Parameters:
      newDim - Bounding box for new image dimension
    • replaceImage

      public void replaceImage(Image fullSizeImage)
      Replace image with full-sized version of same image. Do nothing else than repaint API users should preferably use setImageProvider instead and let this component do lazy loading
      Parameters:
      fullSizeImage -
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • isScaleToMaxSize

      public boolean isScaleToMaxSize()
    • setScaleToMaxSize

      public void setScaleToMaxSize(boolean scaleToMaxSize)
    • paintComponent

      protected void paintComponent(Graphics graphics)
      Overrides:
      paintComponent in class JComponent
    • isZoomeable

      public boolean isZoomeable()
    • zoomToMin

      public void zoomToMin()
      Zoom out so entire image fits within parent Viewport
    • getZoomLevel

      public double getZoomLevel()
      Returns:
      Zoom level. 0 == zoomed out fully (full image showing) 1 == 1:1
    • setZoomLevel

      public void setZoomLevel(double zoomLevel)
      Sets the zoom level. 0 == zoomed out fully (full image showing) 1 == 1:1
      Parameters:
      zoomLevel -
    • changeZoomLevel

      public void changeZoomLevel(double delta)
    • toZoomFactor

      public double toZoomFactor(double zoomLevel)
    • getImageSize

      public Dimension getImageSize()
      Get current image size (the size the image is currently zoomed at)
      Returns:
      See Also:
    • getImageBounds

      public Rectangle getImageBounds()
      Get current image bounds (the bounds the image is currently zoomed at) Top-left corner is usually (0,0), but not when close to fully zoomed out, unless component and image has the same aspect ratio.
      Returns: