我想使用用户定义的图标作为顶点。 如果png文件保存在资源文件夹中,它将起作用,但是我想从本地文件夹中获取png文件
Actions.directory.toString()-字符串形式的文件夹位置-运行
顶点没有任何形状
BufferedImage img = ImageIO.read(new File(Actions.directory.toString() + "/" + Actions.hm.get(key)));
icon = new ImageIcon(img);
System.out.println("icon " +icon);
mxStylesheet stylesheet1 = ShowGraphEditor.graph.getStylesheet();
Hashtable<String, Object> attributestyle = new Hashtable<String, Object>();
attributestyle.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_IMAGE);
attributestyle.put(mxConstants.STYLE_IMAGE, getClass().getResource(Actions.directory.toString() + "/" + Actions.hm.get(key)) );
attributestyle.put(mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_CENTER);
stylesheet1.putCellStyle(eventName, attributestyle);
GraphMenu.getGraph().insertVertex(null, instance.getID().toString(), instance, GraphMenu.x,GraphMenu.y, 80, 30, eventName);
我已经尝试过:
attributestyle.put(mxConstants.STYLE_IMAGE, icon)