0

I want to use a user defined icon as vertex. It works if the png file is saved in the resource folder, however i want to get the png file from a local folder

Actions.directory.toString() - folder location as String - working

the vertex appears without any shape

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);

I've tried:

attributestyle.put(mxConstants.STYLE_IMAGE, icon)

Dushyant Tankariya
  • 1,432
  • 3
  • 11
  • 17
Anna
  • 19
  • 6
  • Is there any exception or log generated for this problem? – Dushyant Tankariya Jun 18 '19 at 13:13
  • @DushyantTankariya no. there is now exception or log generated. the vertex appears but without shape – Anna Jun 18 '19 at 13:15
  • If there is no log or Exception then you need to debug the code line by line and verify the statement `mxConstants.STYLE_IMAGE, icon` that it stores icon or not in attributestyle. If not which means the Image/shape/icon is not loaded yet to java and it's not able to put on your attributestyle. – Dushyant Tankariya Jun 18 '19 at 13:29
  • @DushyantTankariya the icon is loaded, i can use it to load and show it ion my GUI palette. Just inserting as vertex isnt working – Anna Jun 18 '19 at 13:31
  • Refer the [link](https://forum.jgraph.com/vote/4783/down/index.html) and verify with your code if you are missing something. – Dushyant Tankariya Jun 18 '19 at 13:41
  • @DushyantTankariya i know this link. i did it exactly how it is described. And i dont want to store the image in the project. – Anna Jun 18 '19 at 13:43
  • Have you update your graph after adding icon `GraphMenu.getGraph().getModel().endUpdate();` – Dushyant Tankariya Jun 18 '19 at 13:47
  • yes @DushyantTankariya – Anna Jun 18 '19 at 13:54

0 Answers0