Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package hu.kazocsaba.imageviewer;
 
A custom layout manager for the image viewer scroll pane viewport. It is used to set the size of the viewport component with respect to the resize strategy.

Author(s):
Kazó Csaba
class CustomViewportLayout implements LayoutManager {
	private final ImageViewer viewer;
	public CustomViewportLayout(ImageViewer viewer) {
		this. = viewer;
	}
	public void addLayoutComponent(String nameComponent comp) {
	}
	public void removeLayoutComponent(Component comp) {
	}
		if (image == null)
			return new Dimension();
		else
			return new Dimension(image.getWidth(), image.getHeight());
	}
		return new Dimension(4, 4);
	}
	public void layoutContainer(Container parent) {
		JViewport vp = (JViewportparent;
		Component view = vp.getView();
		if (view == null) {
			return;
		}
		Dimension vpSize = vp.getSize();
		Dimension viewSize = new Dimension(view.getPreferredSize());
			viewSize.width = vpSize.width;
			viewSize.height = vpSize.height;
else {
			viewSize.width = Math.max(viewSize.widthvpSize.width);
			viewSize.height = Math.max(viewSize.heightvpSize.height);
		}
		//vp.setViewPosition(new Point());
		vp.setViewSize(viewSize);
	}
New to GrepCode? Check out our FAQ X