Java Jung Fr布局未定位vetices

Java Jung Fr布局未定位vetices,java,jung,Java,Jung,我有以下代码: package jung; import edu.uci.ics.jung.graph.Graph; import edu.uci.ics.jung.graph.DirectedSparseGraph; import edu.uci.ics.jung.algorithms.layout.*; import java.awt.Dimension; import edu.uci.ics.jung.visualization.BasicVisualizationServer; impo

我有以下代码:

package jung;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.algorithms.layout.*;
import java.awt.Dimension;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import javax.swing.JFrame;
/**
 *
 * @author studnet
 */
public class Jung {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Graph<Integer, String> g = new DirectedSparseGraph<Integer, String>();
    g.addVertex((Integer)1);
    g.addVertex((Integer)2);
    g.addVertex((Integer)3); 

    g.addEdge("Edge-A", 1, 2); // Note that Java 1.5 auto-boxes primitives
    g.addEdge("Edge-B", 2, 3);  

    FRLayout2<Integer, String> layout = new FRLayout2(g, new Dimension(600, 600));
    while ( !layout.done() )
        layout.step();
    //Layout<Integer, String> layout = new CircleLayout(g);
    //Layout<Integer, String> layout = new FRLayout(g);
    VisualizationViewer<Integer,String> vv = new VisualizationViewer<Integer,String>(layout);
    //vv.setPreferredSize(new Dimension(600,600)); //Sets the viewing area size

    JFrame frame = new JFrame("Simple Graph View");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);


    // TODO code application logic here
    }
}
package-jung;
导入edu.uci.ics.jung.graph.graph;
导入edu.uci.ics.jung.graph.DirectedSparseGraph;
导入edu.uci.ics.jung.algorithms.layout.*;
导入java.awt.Dimension;
导入edu.uci.ics.jung.visualization.basicvisualization服务器;
导入edu.uci.ics.jung.visualization.VisualizationViewer;
导入javax.swing.JFrame;
/**
*
*@author studnet
*/
公共阶级荣格{
/**
*@param指定命令行参数
*/
公共静态void main(字符串[]args){
图g=新的DirectedSparseGraph();
g、 addVertex((整数)1);
g、 addVertex((整数)2);
g、 addVertex((整数)3);
g、 addEdge(“Edge-A”,1,2);//注意Java1.5自动装箱原语
g、 附录(“边缘B”,2,3);
FRLayout2布局=新FRLayout2(g,新尺寸(600600));
而(!layout.done())
布局。步骤();
//布局=新的环形布局(g);
//布局布局=新的FRG布局;
VisualizationViewer vv=新的VisualizationViewer(布局);
//vv.setPreferredSize(新维度(600600));//设置查看区域大小
JFrame=新JFrame(“简单图形视图”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(vv);
frame.pack();
frame.setVisible(true);
//此处的TODO代码应用程序逻辑
}
}

但是所有的顶点都在左上角,有什么建议吗?

FRLayout2不起作用,我把它切换到FRLayout。

FRLayout2不起作用,我把它切换到FRLayout。

我想你可能需要打电话给我

layout.initialize()
它将运行准备代码

编辑:

我在上述问题上错了。在浏览了
FRLayout
FRLayout2
的差异后,我认为可能存在一些逻辑错误:

fvd1.setLocation(0, 0);
...
fvd1.setLocation(fvd1.getX()+2 * xDelta * forceOverDeltaLength,                 
                 fvd1.getY()+ 2 * yDelta * forceOverDeltaLength);

看起来FRLayout2对原始算法也不太严格。

我相信您可能需要调用

layout.initialize()
它将运行准备代码

编辑:

我在上述问题上错了。在浏览了
FRLayout
FRLayout2
的差异后,我认为可能存在一些逻辑错误:

fvd1.setLocation(0, 0);
...
fvd1.setLocation(fvd1.getX()+2 * xDelta * forceOverDeltaLength,                 
                 fvd1.getY()+ 2 * yDelta * forceOverDeltaLength);

看起来FRLayout2对原始算法也不太严格。

@mihajlv你是对的,在看过FRLayout2代码后,我无法想象为什么JUNG会包含它。@mihajlv你是对的,在看过FRLayout2代码后,我无法想象JUNG为什么会包含它。