labelgettextvertexjgraph

How to get the String (label) of a Vertex by clicking on it (Jgraph)?


In jgraph, is there a function similiar to the .getText(); for a vertex? I need to get the text attached to them in the label.

Thanks.


Solution

  • This example prints you the label of the vertex if you right click on it.

    graphComponent.getGraphControl().addMouseListener(new MouseAdapter() 
    {
        @Override
        public void mousePressed(MouseEvent e) 
        {
            if (SwingUtilities.isRightMouseButton(e))
            {       
                mxCell cell =(mxCell) getGraphComponent().getCellAt(e.getX(), e.getY());
    
                if(cell != null)
                {
                    System.out.println(cell.getValue().toString());
                }
            }
       }
    });