Class ImageView

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
is.codion.swing.common.ui.component.image.ImageView
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public final class ImageView extends JComponent

Displays image bytes fitted to its size, within its insets, the image's proportions kept and centred, an image smaller than the view not enlarged unless ImageView.Builder.enlarge(boolean). Display only: no zooming, panning or mouse handling, see ImagePane for those.

Made for displaying images in table, list or tree cells, as a cell renderer component:

FilterTable<Entity, Attribute<?>> table = FilterTable.builder()
        .model(tableModel)
        .cellRenderer(Country.FLAG, byte[].class, renderer -> renderer
                .component(ImageView.builder().buildValue()))
        .build();
Decoding The bytes are decoded when painted, on the calling thread, and scaled smoothly to the size painted, in device pixels. The scaled image is kept, the decoded one dropped, so a photo costs little memory once displayed. The scaled images are kept by their byte array, the 200 painted most recently, so painting the same array again at the same size decodes nothing, as when a table repaints its rows, each holding its bytes in the same array. So the bytes are not copied: an array changed after being set keeps the image painted from it. The arrays are held weakly, a scaled image dropped once nothing else holds its array, a table row refreshed away for example.

This suits small images: icons, flags and thumbnails. A photo takes the better part of a second to decode, each time its array is first painted, so a table of full size photos is better served by a column of thumbnails.

Bytes no image reader can read, or failing to decode, display nothing. Painting Opaque by default, painting its background, so that a cell renderer's background, the selection's for example, is painted, while a view with no background set takes its parent's. Orientation Where enabled, an image is displayed turned as its EXIF orientation says, as a camera records a photo taken with the camera turned, see ImageView.Builder.orient(boolean) and ORIENT.

See Also: