Problem displaying Icons in JTree
Hi!
To load Icons for each instance of different TreeNodes in the JTree I used following method:
activatedIcon =
new ImageIcon(Toolkit.getDefaultToolkit().getImage(path));
where the path is set as "org/app/images/UnInit.gif"
The separate folder "org/app/images" holds all the icons of the application!
The method works fine when I run the application from an IDE (ex. SAP Netweaver). The JTree is created with Icons!
But when I create a executable JAR file, the JTree is created without icons!
I tried another way with the java.net.URL.
try{
java.net.URL imgURL = getClass().getResource(path);//ImageStates.class.getClassLoader().getResource(path);
if(imgURL !=null){
Image img = ImageIO.read(imgURL);
activatedIcon =new ImageIcon(img);
}
}catch(Exception e){}
First disadvantage for my application in this case is the huge memory consumption! ( I have to create around 5000 nodes at one strech, and that is must)
Secondally, when I run the application with this method, it populates the JTree slowly and shows up nodes with icons. Fine!
But when I create a executable JAR file, the URL at runtime is computed as NULL, and hence rest of the block fails!
Could anyone please help me as of how I could read Images (as Icons for my Nodes) when the application has to be executed as standalone JAR application!

