Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package hu.kazocsaba.imageviewer;
A component showing an image as well as an arbitrary number of overlays.

Kazó Csaba
class LayeredImageView  {
	private final ImageComponent theImage;
	private final JLayeredPane layeredPane;
	public LayeredImageView(ImageComponent theImage) {
		this. = theImage;
		.add(theImage, Integer.valueOf(0));
Returns the component for this layered view.

the Swing component for this view
	public JComponent getComponent() {return ;}

Adds an overlay as the specified layer.

overlay the overlay to add
layer the layer to add the overlay to; higher layers are on top of lower layers; the image resides in layer 0
	public void addOverlay(Overlay overlayint layer) {
		.add(c, Integer.valueOf(layer));
Removes an overlay from the image viewer.

overlay the overlay to remove
java.lang.IllegalArgumentException if the overlay is not in the image viewer
	public void removeOverlay(Overlay overlay) {
			if (c instanceof OverlayComponent && ((OverlayComponent)c).==overlay) {
		throw new IllegalArgumentException("Overlay not part of this viewer");
	private class ScrollableLayeredPane extends JLayeredPane implements Scrollable {
		public int getScrollableUnitIncrement(Rectangle visibleRectint orientationint direction) {
			return 10;
		public int getScrollableBlockIncrement(Rectangle visibleRectint orientationint direction) {
			return 50;
		 * The getScrollableTracksViewportXxx functions below are used by
		 * javax.swing.ScrollPaneLayout to determine whether the scroll bars should
		 * be visible; so these need to be implemented.
		public boolean getScrollableTracksViewportWidth() {
		 * The getPreferredScrollableViewportSize does not seem to be used.
				return getPreferredSize();
				return ((JViewport)javax.swing.SwingUtilities.getAncestorOfClass(JViewport.classthis)).getSize();
New to GrepCode? Check out our FAQ X