1

我正在尝试使用jgraphx. 我有几个mxPointscustomcell

我不仅希望能够绘制矩形或椭圆,还希望能够绘制随机的 n 点多边形。

这可能吗?

这是我使用的代码,但它不起作用。它在线崩溃

currentCustomCell.getGeometry().getPoints().add(point1);

有这个错误Exception in thread AWT-EventQueue-0 java.lang.NullPointerException

每一个帮助将不胜感激。我是java和jgraphx的初学者

mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
currentCustomCell = new mxCell();
currentCustomCell.setVertex(true);
currentCustomCell.setConnectable(false);
try {
    mxPoint point1 = new mxPoint(20.0,20.0);
    currentCustomCell.getGeometry().getPoints().add(point1);
    mxPoint point2 = new mxPoint(20.0,40.0);
    currentCustomCell.getGeometry().getPoints().add(point2);
    mxPoint point3 = new mxPoint(40.0,40.0);
    currentCustomCell.getGeometry().getPoints().add(point3);
    mxPoint point4 = new mxPoint(40.0,20.0);
    currentCustomCell.getGeometry().getPoints().add(point4);
    mxPoint point5 = new mxPoint(50.0,30.0);
    currentCustomCell.getGeometry().getPoints().add(point5);
    graph.addCell(currentCustomCell, parent);
}finally {
    graph.getModel().endUpdate();
}
mxGraphComponent graphComponent = new mxGraphComponent(graph);
graphComponent.refresh();
4

0 回答 0