Results 1 to 3 of 3
  1. #1
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default JFileChooser start in .jar directory

    Hi!

    I'm using a JFileChooser to save a file, but I want the JFileChooser to start in the same directory where the application jar is...

    For example, if the jar of my application name is "Test.jar" and is saved in "c:\app\test.jar", I want the JFileChooser to start in "c:\app\".

    I've tried to do this but It didn't work:

    fc.setCurrentDirectory(new File(Juego.class.getProtectionDomain().getCodeSour ce().getLocation().getPath()));
    where fc is the file chooser...

    Any idea??? I googled it but I couldn't find anything.

    thanks!

  2. #2
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default Openning JFileChooser

    I went through a lot of trouble
    trying to figure this one out
    when I first began using
    JFileChooser. It's not in the
    Java Tutorials.

    The answer, if I understand
    your problem, is very simple
    and plain.


    Java Code:
    //    fc = new JFileChooser("app");                           // this works
    //    fc.setCurrentDirectory(new File("."));                 // this works
    //    fc.setCurrentDirectory(fd.getAbsolutePath());     // this doesn't

  3. #3
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    Thank you!!

    It worked like a charm!

    I spent hours trying to figure out this!!

    bye!

Similar Threads

  1. Jfilechooser
    By greatmajestics in forum Java 2D
    Replies: 5
    Last Post: 03-30-2010, 07:13 PM
  2. help with JFileChooser
    By morgatron in forum New To Java
    Replies: 1
    Last Post: 01-08-2010, 10:00 AM
  3. Replies: 5
    Last Post: 03-20-2009, 11:04 PM
  4. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 06:40 PM
  5. JFileChooser example (selecting a directory)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-14-2008, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •