Java 使用jgraphX绘制n点多边形
我正在尝试使用Java 使用jgraphX绘制n点多边形,java,jgraphx,Java,Jgraphx,我正在尝试使用jgraphx绘制自定义形状。我几乎没有mxPoints和customcell 我希望不仅能画矩形或椭圆,而且能画随机的n点多边形 这可能吗 这是我使用的代码,但它不起作用。它在排队时撞坏了 currentCustomCell.getGeometry().getPoints().add(point1) 线程AWT-EventQueue-0 java.lang.NullPointerException中出现此错误异常 我们将感谢您的帮助。我是java和jgraphx的初学者 mxGr
jgraphx
绘制自定义形状。我几乎没有mxPoints
和customcell
我希望不仅能画矩形或椭圆,而且能画随机的n点多边形
这可能吗
这是我使用的代码,但它不起作用。它在排队时撞坏了
currentCustomCell.getGeometry().getPoints().add(point1)代码>
线程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();
currentCustomCell.getGeometry()==null
,因此currentCustomCell.getGeometry().getPoints()
抛出一个NullPointerException
。