Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-19-2007, 10:26 PM
Member
 
Join Date: Dec 2007
Location: Nashua, NH
Posts: 1
saz25 is on a distinguished road
Send a message via AIM to saz25
Icon initialization problem
Hi,
I am using Netbeans 5.0 to write my Java GUI app.
I have a strange problem. In my java application, I have a JLabel that I'm using as an icon. Actually, I have several of these. A default icon is supposed to appear when the app starts up. When the user clicks on certain buttons (and things happen), the code changes the icon to a different gif file. Here is the code I use to initialize one of them:

sdConfig8.setIcon(new javax.swing.ImageIcon("C:\\filepath\\mycangui\\off .gif"));

When I run my app on my own PC (the one I used to build the app), the icons are all initialized correctly. When I run the app on another PC, these icons are not initialized. So the icon doesn't appear. When the user clicks on the specific button to generate a specific event, the code execution changes the icon to the correct gif. This works fine on all machines.

The issue is why can't I get the icons to initialize on machines other than my development PC?

Thanks in advance,
Steve
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-24-2007, 11:37 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
Directory problem.
Your problem lies here:
Code:
sdConfig8.setIcon(new javax.swing.ImageIcon("C:\\filepath\\mycangui\\off .gif"));
Firstly, not all directories are described by the backslash operator. To make your directory references independent of the operating system that you are running on, use File.seperator. Secondly, the image will not be loaded because it does not automatically exist on the other machine's hard drive at that location. (unless you put it there) It is safer to use file names that are relative to the directory of your application. For example:

Code:
ImageIcon icon = new ImageIcon("data" + File.seperator + "off .gif");
I assume that you intended the space in "off .gif".

Inside your application's directory folder, you could have another folder called "data" with the image in there.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialization and re-assignment of arrays Java Tip java.lang 0 04-14-2008 09:38 PM
initialization value problem ravian New To Java 2 01-28-2008 11:54 AM
How to set an Icon in a Label? Soda New To Java 2 12-07-2007 01:38 PM
Lazy Initialization onegcr New To Java 1 08-14-2007 04:29 PM
log4j initialization arfatkhan Web Frameworks 3 08-10-2007 08:42 PM


All times are GMT +3. The time now is 01:04 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org