Search
Scrolling and Zooming

Enable Scrolling

To enable scrolling, add the DiagramView instance to a JScrollPane container or to a Ruler.

Diagram Size

The diagram size is specified through the Bounds property. Its value is a Rectangle2D instance that specifies the origin of the diagram coordinate system and the diagram size. The scrollbar ranges also depend on the current ZoomFactor.

Automatic Scrolling

The setAutoScroll method enables or disables automatic scrolling. When a user drags a modification handle outside JDiagram visual area while manipulating an item, if automatic scrolling is enabled, the control will scroll its view towards the pointer position. The ScrollZoneSize property defines the size of the area near the view borders that triggers automatic scrolling.

Programmatic Scrolling

To scroll the document contents programmatically, you can use one of the scrollTo, setScrollX or setScrollY methods. To get the current scroll position, call getScrollX and getScrollY. The bringIntoView method scrolls the viewport to ensure that a specific diagram item can be seen in the view.

Scrolling Nodes

The contents of nodes such as ContainerNode, TableNode and TreeViewNode can be scrolled too. Set a container's Scrollable property to allow scrolling, with AutoGrow disabled to let the container's contents overflow. If a table's Scrollable property is set to true, there are up/down scroll buttons displayed in the table's caption bar. By clicking these buttons users can scroll the rows of the table. Scrolling can also be done programmatically using the CurrentRow property.

Zooming

Zooming is controlled by the setZoomFactor method. The zoom factor is expressed as a percentage, 100% meaning no zoom. Higher than 100% makes the diagram items look closer and bigger on the screen - zooming in. Less than 100% makes items look further and smaller on screen - zooming out. To zoom and scroll the view to fit the diagram contents to the control's client area, call zoomToFit. To zoom and scroll the view so it fits a specified rectangular document area to the control's client area, call zoomToFit(Rectangle2D).

Lasso Zoom Tool

The control supports several ways to zoom using lasso tool:

Magnifying

The DiagramView provides an option for zooming in (or out) portions of the diagram through the Magnifier tool. The magnifier tool can be permanently activated by calling setMagnifierEnabled. Alternatively, on-demand magnification through a Magnify value to the view's Behavior property.

The magnification factor can be specified by calling the setMagnifierFactor method. The size of the tool and its border thickness can be set through the MagnifierWidth, MagnifierHeight and MagnifierFrameThickness properties.

Panning

The diagram view can be panned by holding ALT while dragging the mouse with the left button down. To let users pan the view with the left mouse button without using a modifier key, set the Behavior property of DiagramView to PanJDiagram displays the PanCursor while panning.