1

How can I add a mouselistener to a specific vertex in jgraphx?

graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {
                    public void mouseReleased (MouseEvent e1) {

I can use this fro graphcomponent but how can I specify it for a vertex?

user2598911
  • 379
  • 2
  • 6
  • 22

2 Answers2

0

You can call the graphcomponent class's getCellAt(int x, int y) method with the MouseEvent class's getX() and getY() methods. This will return you an object if there is a vertex (or edge) where you clicked, then with a simple comparison you can decide which vertex is it.

Here is an example:

graphComponent.getGraphControl().addMouseListener(new MouseAdapter() 
{
@Override
    public void mouseReleased(MouseEvent e) 
    {    
        mxCell cell =(mxCell) getGraphComponent().getCellAt(e.getX(), e.getY());
        if(cell != null && cell.equals(YOUR_VERTEX))
        {
            //specific thing you want to do on click
        }
    }
});
Bence Kaulics
  • 7,066
  • 7
  • 33
  • 63
0

You could create an mxCellHandler for a given cell state, i.e. your specific vertex. You could check the createHandler() of the mxGraphComponent class.

Hope this helps.

sysoutkoula
  • 340
  • 1
  • 10