Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JCombobox Rendering Problem

Reply
Thread Tools

JCombobox Rendering Problem

 
 
Mkhululi.Tyukala@gmail.com
Guest
Posts: n/a
 
      11-18-2008
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?
 
Reply With Quote
 
 
 
 
Jan Thomä
Guest
Posts: n/a
 
      11-18-2008
On 2008-11-18 07:52:47 +0100, 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
IE6 SP1 rendering vs IE6 SP2 rendering Peter Mount HTML 4 01-31-2006 08:01 AM
JComboBox problem - only one element Genevieve Java 13 07-06-2005 02:31 PM
Problem with JComboBox Derek Java 3 05-09-2005 10:43 PM
JComboBox problem Allan Mullan Java 0 04-18-2004 12:42 PM
JComboBox problem, pse help! Tobi Krausl Java 6 12-01-2003 08:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57