3

I have a mouseMoved(MouseEvent e) method with the coordinates e.getX() and e.getY(). Now I want to check if the mouse is over a vertex. Is there a way to do this?

I don't want to check if the cell (vertex) is selected, I only want to check if the mouse is over one vertex.

mGraph = new mxGraph();

// create vertexes ...

mGraphComponent = new mxGraphComponent(mGraph);

//mGraphComponent.getGraphControl().addMouseMotionListener(new MouseAdapter() {
mGraphComponent.getGraphControl().addMouseMotionListener(new mxMouseAdapter() {
    @Override
    public void mouseMoved(MouseEvent e)
    {
        System.out.println(Integer.toString(e.getX()) + " " +
            Integer.toString(e.getY()));

        // here I want to check if the mouse position is over a cell
        // I only want to check if the mouse is over one (or more?) cells
    }
}
);

mPanel.add(mGraphComponent);
Frodo Baggins
  • 8,290
  • 6
  • 45
  • 55
user1047271
  • 311
  • 2
  • 9

1 Answers1

2

You can do this like so:

Object cell = mGraphComponent.getCellAt(e.getX(), e.getY(), false);

cell should be a mxCell and then you can use model.isVertex() or model.isEdge().

Frodo Baggins
  • 8,290
  • 6
  • 45
  • 55
Xavier M.
  • 136
  • 1
  • 7