How to update scroll bars and the scrollable area of a Graph2DView

Troubleshooting

Summary

Updating scroll bars and the scrollable area of a Graph2DView after graph changes outside of the viewable area
For a better user experience, please go to the integrated documentation viewer to read this article.

Description

One of the first things users learn when working with Graph2DView is the need to notify the view of changes in the underlying graph structure. Usually this is done by invoking updateView(), but sometimes updateView() is not enough. For instance, when your graph aquires a new node, which lies outside of the view's world rectangle (i.e. the view's scrollable area). To be able to scroll to the newly added node, you need update Graph2DView's world rectangle to include said node. This can be done by simply calling updateWorldRect() prior to the usual call of updateView(). This will effectively union the view's old world rectangle with the underlying graph's bounding box. Another possibility is to set the view's world rectangle explicitly with public void setWorldRect(int x, int y, int w, int h) (again followed by a call to updateView()).

Categories this article belongs to:
yFiles for Java > yFiles Viewer > Displaying and Editing Graphs > View Implementations
Applies to:
yFiles for Java 2: 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12, 2.13, 2.14, 2.15, 2.16, 2.17, 2.18
Keywords:
worldRect - world rectangle - scrollbar - scrollbars - scroll bar - scroll bars - graph navigation