JCombobox Rendering Problem

Discussion in 'Java' started by Mkhululi.Tyukala@gmail.com, Nov 18, 2008.

  1. Guest

    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?
     
    , Nov 18, 2008
    #1
    1. Advertising

  2. Jan Thomä Guest

    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
     
    Jan Thomä, Nov 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tobi Krausl

    JComboBox problem, pse help!

    Tobi Krausl, Nov 27, 2003, in forum: Java
    Replies:
    6
    Views:
    4,325
    Tobi Krausl
    Dec 1, 2003
  2. Allan Mullan

    JComboBox problem

    Allan Mullan, Apr 18, 2004, in forum: Java
    Replies:
    0
    Views:
    534
    Allan Mullan
    Apr 18, 2004
  3. Derek

    Problem with JComboBox

    Derek, May 9, 2005, in forum: Java
    Replies:
    3
    Views:
    858
  4. Genevieve
    Replies:
    13
    Views:
    3,751
    Genevieve
    Jul 6, 2005
  5. Peter Mount
    Replies:
    4
    Views:
    984
    Peter Mount
    Jan 31, 2006
Loading...

Share This Page