If the user resizes the window containing a VisualizationViewer, then the following code will support the Graph being dynamically resized to accommodate the user's preference (although, it would be nice if this happened automatically).
container.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent ce) {
graphVisualiser.getGraphLayout().setSize(getSize());
}
});
However, if the graphVisualiser is using an AggregateLayout, anything held in one of the subLayouts will remain fixed in its original position.
Please support resize for AggregateLayout.
Workaround: Separately store the locations of all the subLayout centres, and then scaling them when the size is changed in the Listener above.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
Got a workaround!
Subclass (or define inline when instantiating) AggregateLayout to @Override setSize
@Override
public void setSize(Dimension size) {
Dimension oldSize = getSize();
super.setSize(size);
size = getSize();
if (size == null || oldSize == null) {
return;
}
int xOffset = (size.width - oldSize.width) / 2;
int yOffset = (size.height - oldSize.height) / 2;
for (Entry<Layout<Note, Weight>, Point2D> entry : getLayouts().entrySet()) {
double x = entry.getValue().getX() + xOffset;
double y = entry.getValue().getY() + yOffset;
entry.setValue(new Point2D.Double(x, y));
}
}