2

在我的应用程序中,我想使用 JUNG 显示生成的图表。它产生 JPanel 对象作为输出。所以,我认为这只是向面板添加一个组件的问题。但是该图是在其父面板之外绘制的。屏幕截图: 截屏 如何将图形限制为仅在可见区域内?我用来将图形添加到面板的代码是这样的(边框是让我看到面板边框的,尽管由于某种原因它没有显示):

    Layout<Object, String> layout = new CircleLayout<Object, String> (graphProvider.getGraph());
    layout.setSize(panel.getMarketGraphPane().getPreferredSize());
    BasicVisualizationServer<Object,String> graphPanel = new BasicVisualizationServer<Object,String>(layout);
    graphPanel.setBorder(new EtchedBorder());
    graphPanel.setSize(panel.getMarketGraphPane().getPreferredSize());
    panel.getMarketGraphPane().add(graphPanel, BorderLayout.CENTER);
    panel.getMarketGraphPane().revalidate();
4

2 回答 2

3

too little informations for the actual image

1 depends

  • what Size returns (generated graph, by using JUNG), are you set there setSize(int, int) too,

  • if is graph resiziable,

2) remove

  • layout.setSize(panel.getMarketGraphPane().getPreferredSize());

and

  • graphPanel.setSize(panel.getMarketGraphPane().getPreferredSize());

you can't to setSize for Object placed to the BorderLayout.CENTER, and I think that is possible directly put (generated graph, using JUNG. It produces JPanel object) to the BorderLayout.CENTER area, try that maybe your twice setSize generated some mess

and then you can call only

panel.add(graphPanel, BorderLayout.CENTER);
panel.revalidate();
panel.repaint();

3) another two choises (without clean-up setSize)

于 2011-10-18T20:10:33.000 回答
2

使用 GraphZoomScrollPane 为 VisualizationViewer 对象添加可缩放的图形滚动窗格容器,如下所示:

GraphZoomScrollPane pane = new GraphZoomScrollPane(visualizationViewer);
JPanel panel = new JPanel();
BorderLayout panelMapLayout = new BorderLayout();
panel.setLayout(panelMapLayout);
panel.add(pane, BorderLayout.CENTER);
于 2011-10-18T22:37:19.867 回答