public class JImageViewer extends JComponent implements Printable
JImageViewer renders an image in the centre of the component. This image can
be scaled, and a transparency checkboard can also be drawn behind it.
As an extra feature, the image can be dragged with the mouse if the viewer is in a JScrollPane.
This class also implements the Printable interface since R13.
| Modifier and Type | Class and Description |
|---|---|
static class |
JImageViewer.Autoscale |
static class |
JImageViewer.Quality |
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategylistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTNO_SUCH_PAGE, PAGE_EXISTSABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JImageViewer()
Creates an empty
JImageViewer. |
JImageViewer(Image image)
Creates a
JImageViewer showing the given Image. |
JImageViewer(ImageIcon icon)
Creates a
JImageViewer showing the given ImageIcon. |
JImageViewer(InputStream is)
Creates a
JImageViewer showing an image that is read from the given
InputStream. |
JImageViewer(URL url)
Creates a
JImageViewer showing an image that is read from the given
URL. |
| Modifier and Type | Method and Description |
|---|---|
JImageViewer.Autoscale |
getAutoscale()
Gets the current autoscale mode.
|
Color |
getCheckboardColor()
Gets the transparency checkboard color.
|
Image |
getImage()
Gets the
Image that is currently set. |
Dimension |
getMinimumSize() |
Dimension |
getPreferredSize() |
JImageViewer.Quality |
getQuality()
Gets the current scaling quality.
|
protected Dimension |
getScaledDimension()
Gets the final
Dimension of the image after proper scaling was applied. |
float |
getZoomFactor()
Gets the current zoom factor.
|
boolean |
isCheckboard()
Checks if the transparency checkboard is to be drawn.
|
protected void |
paintComponent(Graphics g) |
int |
print(Graphics graphics,
PageFormat pageFormat,
int pageIndex) |
void |
setAutoscale(JImageViewer.Autoscale autoscale)
Sets the autoscale mode.
|
void |
setCheckboard(boolean checkboard)
Draws the transparency checkboard.
|
void |
setCheckboardColor(Color color)
Sets the transparency checkboard color.
|
void |
setImage(Image img)
Sets a new
Image to be shown. |
void |
setImage(ImageIcon icon)
Sets a new
ImageIcon to be shown. |
void |
setImage(InputStream in)
Sets a new image that is to be read from the
InputStream. |
void |
setImage(URL url)
Sets a new image that is to be read from the
URL. |
protected void |
setQuality(Graphics2D g2d,
JImageViewer.Quality quality)
Sets the rendering hints according to the quality.
|
void |
setQuality(JImageViewer.Quality quality)
Sets the scaling quality.
|
void |
setZoomFactor(float zoom)
Sets the zoom factor for the shown image.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic JImageViewer()
JImageViewer.public JImageViewer(Image image)
JImageViewer showing the given Image.image - Image to be shown.public JImageViewer(ImageIcon icon)
JImageViewer showing the given ImageIcon.icon - ImageIcon to be shown.public JImageViewer(InputStream is) throws IOException
JImageViewer showing an image that is read from the given
InputStream.is - InputStream to read the image data from.IOException - if the stream could not be read.public JImageViewer(URL url)
JImageViewer showing an image that is read from the given
URL.url - URL to read the image data from.public void setImage(Image img)
Image to be shown.img - New Image to be shown.public void setImage(ImageIcon icon)
ImageIcon to be shown. This is a convenience method that will
just invoke ImageIcon.getImage().icon - New ImageIcon to be shown.public void setImage(InputStream in) throws IOException
InputStream. No fancy image
formats are supported, just the one that are supported by ImageIO.in - InputStream providing the image data.IOException - if the image could not be read.public void setImage(URL url)
URL. No fancy image formats
are supported, just the one that are supported by ImageIO.url - URL to read the image from.public Image getImage()
Image that is currently set.Image, or null if none was set.public void setCheckboard(boolean checkboard)
By default, no transparency checkboard is shown since it slows down the performance and might confuse the user.
checkboard - true: show transparency checkboard.public boolean isCheckboard()
true: show transparency checkboard.public void setCheckboardColor(Color color)
null is passed in
here), the background color's Color.brighter() is used for the bright
fields. For the dark fields, Component.getBackground() is always used if this
component is opaque.color - Checkboard Color, null means default color.public Color getCheckboardColor()
Color, or null if the default color is
used.public void setAutoscale(JImageViewer.Autoscale autoscale)
JImageViewer.Autoscale.OFF, so you can embed a
JImageViewer into a JScrollPane.autoscale - The new JImageViewer.Autoscale mode.public JImageViewer.Autoscale getAutoscale()
public void setZoomFactor(float zoom)
NOTE that JImageViewer.Autoscale.OFF must be set in order to use zooming. This
might change in future releases though.
zoom - Zoom factor. Default is 1.0f.public float getZoomFactor()
public void setQuality(JImageViewer.Quality quality)
quality - New scaling quality.public JImageViewer.Quality getQuality()
protected Dimension getScaledDimension()
Dimension of the image after proper scaling was applied.public Dimension getMinimumSize()
getMinimumSize in class JComponentpublic Dimension getPreferredSize()
getPreferredSize in class JComponentprotected void paintComponent(Graphics g)
paintComponent in class JComponentpublic int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
protected void setQuality(Graphics2D g2d, JImageViewer.Quality quality)
g2d - Graphics2D to set the rendering hints.quality - JImageViewer.Quality desired.Copyright © 2004–2016. All rights reserved.