I have a jung tree displayed in a JPanel. The constructor of my tree looks like this:
Forest graph = new DelegateForest
ScalingControl is not good method if you use Mouse Transformer.
Try to:
// for zoom:
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setScale(scale_x1, scale_y1, vv.getCenter());
// for out:
vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setScale(scale_x2, scale_y2, vv.getCenter());
ScalingControl scaler = new CrossoverScalingControl();
public void zoomIn() {
setZoom(1);
}
public void zoomOut() {
setZoom(-1);
}
private void setZoom(int amount) {
scaler.scale(vv, amount > 0 ? 1.1f : 1 / 1.1f, vv.getCenter());
}
To fits the graph on the window, you can calculate the diference between the graph size and the panel size, and call the setZoom() method passing the factor of diference.