I have a jung tree displayed in a JPanel. The constructor of my tree looks like this:
Forest graph = new DelegateForest
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.