用jgraphX绘制n个点多边形

时间:2013-12-17 00:08:53

标签: java jgraphx

我正在尝试使用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();

0 个答案:

没有答案