我正在尝试使用jgraphx
绘制自定义形状。我的mxPoints
和customcell
很少。
我希望不仅可以绘制矩形或椭圆,还可以绘制随机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();