473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

using resource files in a relocatable fashion - HELP

18
I am building an app within NetBeans and I am trying to make my use of resource files relocatable, so when I run my app on a different system it still finds the resource files.

My problem is that I use a graphics file xxx.PNG that I need to dynamically paint on a JPanel. I’ve set it up as follows (the application is called MiscDemoApp):

Image xxxImage;
static String resourcePath;

org.jdesktop.application.ResourceMap resourceMap =
MiscDemoApp.getApplication().getContext().getResou rceMap(MiscDemoView.class);

// the file path location for all the PNG files is stored in a Property field
resourcePath = new String (resourceMap.getString("FileLocation"));
xxxImage=Toolkit.getDefaultToolkit().getImage(reso urcePath + "xxx.png");

Then, within the resources I have:

Source Packages /
miscdemo.resources /
MiscDemoView.properties /
FileLocation=C:/Documents and Settings/Chris/My
Documents/NetBeansProjects/MiscDemo/src/miscdemo/resources/

I put xxx.PNG in the directory above (…/miscdemo/resources/xxx.PNG) and this runs OK on my WinXP system … it finds the PNG OK. When I take my JAR file over to a different PC running WinVista it does not appear to find the PNG. I copied over my entire NetBeans project, which resides in:

c:\users\Chris\My Documents\NetBeansProjects\MiscDemo

… thus the “FileLocation” resource string is no longer valid on the other system - the file path is slightly different. The obvious answer is to make the location of the PNG relative somehow, and therefore system-independent.

So the next thing I tried was (as suggested by an example on the Web):

try {
xxxImage = javax.imageio.ImageIO.read(MiscDemoApp.class.getRe source("src/miscdemo/resources/xxx.png"));
} catch (java.io.IOException e) {

}

… but this seems to return a NULL to the ImageIO.read() call.

HELP – there has to be an easier way to use local resources. [I realize Java needs to accommodate the complexities of Web resources usage, etc. … but it seems quite complex in comparison to Visual Studio where I just needed to create a *.rc resource file and everything else was handled.

[NOTE: in cases where I’ve needed simply to paint a static image, I’ve used code such as:

logoLabel = new javax.swing.JLabel();
logoLabel.setIcon(resourceMap.getIcon("logoLabel.i con"));
logoLabel.setName("logoLabel");

jPanel3.setLayout(null);
jPanel3.add (logoLabel);
logoLabel.setBounds (10,10,190,190);

… where the properties contain:
logoLabel.icon=MiscLogoSmall.png

This seems to work on both the WinXP and Vista systems (… and doesn’t seem to need a file path to locate the resource). So I’m looking for the same behavior with my xxxImage. I don't want to use a JLabel for it, I want to paint it as such:

class GraphPanel extends javax.swing.JPanel {
@Override
public void paintComponent(java.awt.Graphics g){
super.paintComponent(g);
// paint the image
g.drawImage (xxxImage, …
]



Thanks for any help,
Chris
Jan 20 '10 #1
1 2232
pbrockway2
151 Expert 100+
@dorito
Seems to? If xxxImage actually does end up null the most common reason would be that the image (either file or jar archive entry) is not at the place you specified.

You can get more information by (1) Printing the URL returned by getResource() to see where you are actually looking for the image and (2) Doing something in the catch block: at a minimum e.printStackTrace().
Jan 20 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dennis Hore | last post by:
I'm trying to install Nick Patavalis' ppgplot package on Mac OS X 10.3 with python 2.3. I first sent this message to Nick, but he said he doesn't have any experience with the Mac platform. ...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
12
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
1
by: Kaworu | last post by:
Hi, at first time I want to apologize for my English. I need to change the language of my app and I like to do it changin the caption of the controls in the resource.rc file, or having on...
0
by: vivek | last post by:
localization of lang. using resource files resides in the global resources folder (App_GlobalResources). Currently In my application, I need to have different language resource files in global...
1
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. ...
0
by: screenbert | last post by:
Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes creating and deleting Scopes, SuperScopes,...
7
by: craig | last post by:
....quick question for anyone who might have some experience with .net resource files in VS 2003. I have an application that is not localized, but I would still like to be able to place all of...
2
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.