Search
Alignment Grid

JDiagram provides an alignment grid to help users place diagram items more precisely. To activate the grid, use the setAlignToGrid method. If the grid is active while an item is being created or modified, the item's control-points are aligned to the nearest grid points. The distance between adjacent grid points is set by calling the setGridSizeX and setGridSizeY methods. The GridOffsetX and GridOffsetY properties allow specifying the horizontal and vertical offset of the first point in the alignment grid.

Items created or modified by a user are automatically aligned to the grid. However, if items are placed in the diagram programmatically, their coordinates are set to the specified positions without aligning. In such cases use alignPointToGrid if items must be placed exactly at grid points.

The method setShowGrid can be used to turn the grid visible or invisible. The color and style of a visible grid can be adjusted through the setGridColor and setGridStyle methods respectively.