I am trying to draw custom shape with jgraphx
. I have few mxPoints
and customcell
.
I want to be able not just draw rectangles or ellipses, but draw random n point polygon too.
Is this possible?
Here is code, which I use, but it doesn't work. It crashes at line
currentCustomCell.getGeometry().getPoints().add(point1);
with this error Exception in thread AWT-EventQueue-0 java.lang.NullPointerException
.
Every help will be appreciated. I am beginner in java and 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();