Reputation: 487
I want to visualize some graphs in a frame (actually JInternalFrame, since I have also other stuff outside the graph) using the JUNG library. There are many codes in my class, but I just give the short version, how I create the components to show the graph:
And the end effect is, there are scroll bars shown, but even if the graph is bigger than the frame, the scroll bars are not enabled. If I reduce the size of the frame, the scroll bars are enabled, but I cannot scroll to see the whole graph. So no matter how big the frame is, I cannot see the whole graph.
I also tried setting the size of the layout, the size of the VisualizationViewer, but did not work.
Could some one please tell me what I missed?
Upvotes: 2
Views: 832
Reputation: 10204
In case anyone still needs the solution:
JFrame jFrame=new JFrame("Graph");
Dimension preferredGraphSize=new Dimension(2500,2500);
Layout<V,E> layout=new FRLayout<>(graph, preferredGraphSize);
VisualizationViewer<V,E> visualizationViewer=new VisualizationViewer<>(layout, preferredGraphSize);
ScrollPane scrollPane=new ScrollPane();
scrollPane.add(visualizationViewer);
jFrame.getContentPane().add(scrollPane);
jFrame.pack();
jFrame.setVisible(true);
We set the preferred size for layout and VisualizationViewer
, wrap VisualizationViewer
inside a ScrollPane
and scrolling works.
Upvotes: 1
Reputation: 487
Found a workaround at least to my specific situation:
I implemented the VisualizationViewer.GraphMouse, when the mouse clicks on empty space, move the whole graph, so that one can see the invisible part. So a scroll pane is not needed.
But if s scroll pane is indeed needed, the problem is still open.
Upvotes: 0