Search code examples
javajung

JUNG2: put vertex at fixed point


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.


Solution

  • 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!