Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JCombobox Rendering Problem (http://www.velocityreviews.com/forums/t645034-jcombobox-rendering-problem.html)

Mkhululi.Tyukala@gmail.com 11-18-2008 06:52 AM

JCombobox Rendering Problem
 
Hi All,

I am writing a swing application with the following functionality:
(1) There is a base class that supports things like changing the look
and feel – this is done via a JDialog that loads all the installed
lafs from which the user selects a choice.
(2) Enables the user to set/change the physical database properties –
location, password usernames and the like. -
The idea is that when the application starts up for the first time the
user will be asked to provide the database settings and then they will
be stored in a file and then every time the application starts the
settings will be loaded from this file. This works out fine!!!!!!!!!

Now here is the problem:
All the above is supported by an abstract class that extends JFrame
(I’ve put abstract after testing) - MySuperFrame. After testing, I
packaged this class together with other utility classes into a jar
file.
So my application which inherits from MySuperFrame fails on start-up
with an exception that the database settings file cannot be found –
And I know that it is in the jar file.

I think that my problem is the path and nothing but the path – or
relative path.+

This is the structure of my project:
There is the src and the bin directories and then there is an external
folder (not a package inside these two folders) called files (this is
where my database settings file is stored).
How do I solve this problem?
How do I make sure my application loads the settings file regardless
of where it is? I thought of passing the database settings file to a
constructor of a database settings dialog class. But I don’t know how
to sort out the path issue.

Please give me advice on how to implement that?

Jan Thomä 11-18-2008 11:57 AM

Re: JCombobox Rendering Problem
 
On 2008-11-18 07:52:47 +0100, Mkhululi.Tyukala@gmail.com said:

> How do I make sure my application loads the settings file regardless
> of where it is? I thought of passing the database settings file to a
> constructor of a database settings dialog class. But I don’t know how
> to sort out the path issue.



One possible approach might be to use the classloader for locating the
file. Eg. you have a jar with the following contents

- META-INF
- com
- yourproject
- dbsettings.properties


Put this jar file into the classpath of your application. Then you can
use the following code to look it up:


public static void main(String args[]) {
InputStream is =
MySuperFrame.class.getRessourceAsStream("/dbsettings.properties");
Properties p = new Properties();
p.load(is);

// now p contains all your settings
}

This should work regardless of the actual location of the properties
file, as long as it is in your classpath. You can put it inside a jar
or even put it plain into a folder, as long as you put that folder into
your classpath.

Hope that helps.

Best regards,
Jan



All times are GMT. The time now is 04:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.