3

我有一个坐标为 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);
4

1 回答 1

2

你可以这样做:

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

单元格应该是 amxCell然后你可以使用model.isVertex()or model.isEdge()

于 2013-08-09T20:28:23.027 回答