0

I want to show image in table using html.it display in netbeans but when I create a jar it not works why?

sample code..

  jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] {},new String [] {"From"}));
    DefaultTableModel tmodel= (DefaultTableModel) jTable1.getModel();
   URL url = getClass().getClassLoader().getResource("images/sms.png");

 ***String  tab=  "<html><table style='width:100%; table-layout:fixed'><tr><td style='width: 30px' rowspan=2 ><img src='"+ url+ "' width=36 height=36/> </td><td font color='#ffffff' style='width: 110px'><font size='4'>"+namePerson+"</font></td></tr></table></html>";***

  tmodel.addRow(new Object[] {tab});               
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • it's a file url. if you're then loading this from a website, file urls would be a security violation and get ignored. and if it's locally loaded, then it's an invalid file url anyways. it'd be `file:///d:/...` – Marc B Apr 09 '15 at 14:45
  • **String tab= "
    "+namePerson+""+myDate+"
    "+str1+"
    ";**
    – user3663433 Apr 09 '15 at 14:52
  • The path must be case-sensitive. You might try also `URL url = SomeClassInJar.class.getResource("/images/sms.png");` – Joop Eggen Apr 09 '15 at 15:16
  • see [Loading images from jars for Swing HTML](https://stackoverflow.com/questions/6373621/loading-images-from-jars-for-swing-html) for a solution – domids Sep 26 '17 at 09:40

1 Answers1

0

Most likely, you do not have the correct path for the file in the jar. A few things to check:

  1. If you unzip the .jar, is the image file present? For example, maven will only package the resources under src/main/resources. I do not know in your case how you add it to your jar, but please verify.
  2. If you unzip the .jar, is the image file in the location that you expected? Often IDEs will flatten the classpath or at least treat it slightly differently than the actual .jar.
Math
  • 36
  • 2