首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jung FRLayout不定位顶点

Jung FRLayout不定位顶点
EN

Stack Overflow用户
提问于 2013-05-28 00:30:15
回答 2查看 368关注 0票数 1

我有以下代码:

代码语言:javascript
复制
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
    }
}

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-28 00:38:08

我把FRLayout2的工作传给了FRLayout。

票数 0
EN

Stack Overflow用户

发布于 2013-05-29 23:47:07

我想你可能得打个电话

代码语言:javascript
复制
layout.initialize()

它将运行准备代码。

编辑:

我对上述问题的看法是错误的。在浏览了FRLayoutFRLayout2的不同之处后,我认为其中可能存在一些逻辑错误:

代码语言:javascript
复制
fvd1.setLocation(0, 0);
...
fvd1.setLocation(fvd1.getX()+2 * xDelta * forceOverDeltaLength,                 
                 fvd1.getY()+ 2 * yDelta * forceOverDeltaLength);

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16777195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档