This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

custom DefaultListCellRenderer only works on one PC  RSS feed

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet with several JLists. I implemented a custom DefaultListCellRenderer to display an icon in front of each item in the JList. This works successfully in the applet when run in my test environment in RAD. When I export the applet as a jar and add it to my WebSphere application, it installs successfully and displays the icons in the JLists - but only on my PC. I can't get it to work on any other PC. I added a println, which I can see in the Java console on other PCs, and it matches the output from that on my PC. If you have any tips, I'd really appreciate it.

I am using JDK 1.5.

 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
verduka fox wrote:This works successfully in the applet when run in my test environment in RAD. When I export the applet as a jar and add it to my WebSphere application, it installs successfully and displays the icons in the JLists - but only on my PC. I can't get it to work on any other PC. I added a println, which I can see in the Java console on other PCs, and it matches the output from that on my PC. If you have any tips, I'd really appreciate it.

Try printing icon.getIconWidth() and see if it still matches.

From what you've told us, I see no reason to expect that a file at /images/icon_new.gif exists on the other machines.

Typically you would add the image files to your jar and load them via getResource().
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,

Thanks so much for your response. I had the images in the jar from the beginning, I just forgot to mention this in my original post.

I changed my code from:

icon = new ImageIcon("/images/icon_hospital.gif");

to:

java.net.URL imageURL = IconListRenderer.class.getResource("/images/icon_hospital.gif");
if (imageURL != null)
{
icon = new ImageIcon(imageURL);
}

and it works now. Thanks so much for the tip! I appreciate your helpfulness.

 
Brian Cole
Author
Ranch Hand
Posts: 947
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
verduka fox wrote:it works now. Thanks so much for the tip! I appreciate your helpfulness.



You're welcome.

By the way, you probably don't want to instantiate an ImageIcon on every call to getListCellRendererComponent(). That could be pretty slow, especially if your table is large.

I think it would be better to load your three ImageIcons when you instantiate your IconListRenderer instance, then refer to them over and over in getListCellRendererComponent().
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!