Weixiang Guan
Weixiang Guan

Reputation: 487

JUNG scrollable VisualizationViewer

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:

  1. Create a layout of the graph, depending on the type of the graph, I have different layouts created
  2. Create a VisualizationViewer with the layout as parameter.
  3. Create a GraphZoomScrollPane containing the VisualitationViewer.
  4. Set the GraphZoomScrollPane as the content pane of the frame.

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

Answers (2)

Andrii Chernenko
Andrii Chernenko

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

Weixiang Guan
Weixiang Guan

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

Related Questions