I try write plugin to NetBeans IDE. But I have problem with finding correct path to some image:
Here is my project tree structure:
And testing code like this dosent show icon wePagesBadge.gif
ImageIcon image = new ImageIcon("webPagesBadge.gif");
JOptionPane.showMessageDialog(null, "Some Messsage","Example",JOptionPane.INFORMATION_MESSAGE,image);
of course when i put this image into root folder where i have on my local computer installed netbeans the icon appear in JOptionPane. This path is
C:\Program Files\NetBeans 8.0
Other example is when i not using Maven Project Type to develop plugin but Netbeans Module Project Type:
this time the image appear on the JOptionPane. I spent a lot time to find answer and I don't have idea how to fix it.
It is a bad practice to put resources under the source package
create a folder my the name of resources under src/main/resources and then try to read it using
className.class.getClassLoader().getResource("yourImageFile");
So this should do the work
ImageIcon imageIcon = new ImageIcon(PDFGenerator.class
.getClassLoader()
.getResource("yourIcon.gif"));
i found answer how to fix it. Insted of using code like:
ImageIcon image = new ImageIcon("webPagesBadge.gif");
JOptionPane.showMessageDialog(null, "Some Messsage","Example",JOptionPane.INFORMATION_MESSAGE,image);
i use
ImageIcon image = new ImageIcon(ImageUtilities.loadImage("webPagesBadge.gif"));
JOptionPane.showMessageDialog(null, "Some Messsage","Example",JOptionPane.INFORMATION_MESSAGE,image);
and i put image into:
Method which i use to load image
ImageUtilities.loadImage("webPagesBadge.gif")
is from org.openide.util.ImageUtilities
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With