Reputation: 1685
I'm using the JUNG framework, with the FRLayout. Like this:
layout = new FRLayout<String, Number>(graph);
preferredSize = new Dimension(600, 600);
final VisualizationModel<String, Number> visualizationModel =
new DefaultVisualizationModel<String, Number>(layout, preferredSize);
vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
I've placed this in a GraphZoomScrollPane. I can zoom in, zoom out, move the graph around until it looks just like I want it, but I would like it to be like that when I start my Swing application.
What I want exactly, is that the graph's PreferredSize dynamically adjusts based on the graph size, so that when I load large graphs, I don't have to zoom in a billion times before the vertices don't overlap anymore.
What doesn't fit in my panel should normally then "disappear" behind the scrollbars.
Upvotes: 3
Views: 1426
Reputation: 25116
You can scale it programmatically using the following:
double amount = 1.0; // Or negative to zoom out.
ScalingControl scaler = new CrossoverScalingControl();
scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());
Note: I got this from StackOverflow before (so the credit for this code is not mine), but I can't seem to find the original question.
EDIT:
I found it:
How to manually set the zoom on a Jung visualisation?
Upvotes: 1