0

I would like to ask if is there any way to put vertex at specific point (x,y) at canvas. I would like to start an app with graph already built, however using g.addVertex(1) adds vertex to graph but it is being put at canvas at random points.

2 Answers2

0

http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/algorithms/layout/AbstractLayout.html

setLocation followed by lock.

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18
0
public static class MyVertex  {
    private String name;
    private int vIndex;
    private boolean visited = false;
    private int distance = 0;

    private double x;
    private double y;

    public MyVertex(String name, int vIndex) {
        this.name = name;
        this.vIndex = vIndex;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getX() {
        return x;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getY() {
        return y;
    }

    public String getName() {
        return name;
    }

}

Maybe this will help you? I used it for my project, and it works great!

ZeeLoony
  • 60
  • 7
  • 1
    In order for this to work, you'd have to provide a MyVertex-specific Layout implementation that read the location from the MyVertex data. It works, but it's not very general. If you have fixed points that you want to use, that's what StaticLayout is for. – Joshua O'Madadhain Jun 08 '13 at 01:39