我有一个坐标为e.getX()和e.getY()的mouseMoved(MouseEvent e)方法。
现在,我要检查鼠标是否在顶点上。有没有办法做到这一点?

我不想检查是否选择了单元格(顶点),只想检查鼠标是否在一个顶点上。

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);

最佳答案

您可以这样做:

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

单元格应为mxCell,然后可以使用model.isVertex()model.isEdge()

10-08 11:43