Results 1 to 9 of 9
  1. #1
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default How to set the path when i Browse Using JFileChooser?

    I am making a program in I'm using Netbeans my Form contains TextField and Buttons. this Buttons is to browse Files and Directories for the help of JFileChooser. and the TextFields is to output the path of the files or the directories chosen.

    and i have in my mind that when I write the currentpath in the TextField for
    example "C:\" then when i click the button to browse i want to do is automatically the path is in the C:\ instead of "My Documents" path. because when i click the button to browse the default path is on My Documents. Is this possible.?

    any help?

    Thanks in advance for help

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default

    thanks Fubarable

  4. #4
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default

    Java Code:
    JFileChooser Chooser = new JFileChooser();
            Chooser.setMultiSelectionEnabled(true);
            Chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int result = Chooser.showDialog(this,"Open/Save");
            if(result == JFileChooser.APPROVE_OPTION)
            {
                File file = Chooser.getSelectedFile();
                TxtFld.setText(file.toString());
                
            }
    the code above to browse. but the default path is in "My Documents". what should i do.?

  5. #5
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    Constructor Summary
    JFileChooser()
    Constructs a JFileChooser pointing to the user's default directory.
    --------------------------------
    JFileChooser(File currentDirectory)
    Constructs a JFileChooser using the given File as the path.
    Hope it helped :)

  6. #6
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default

    RaIdEn? where should i put the "File currentDirectory"? you can give an example?
    Last edited by mlibot; 01-21-2010 at 06:57 AM.

  7. #7
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    i meant..

    JFileChooser (Java 2 Platform SE v1.4.2)

    File (Java 2 Platform SE v1.4.2)

    this shld make your default directory as C:\

    instead of

    Java Code:
    JFileChooser Chooser = new JFileChooser();
    do this

    Java Code:
    JFileChooser Chooser = new JFileChooser(new File("C:\\"));

  8. #8
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default

    Thanks RaIdEn it helps. and thanks also for the link

  9. #9
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

Similar Threads

  1. create gui browse folder destination
    By gisler in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 04:13 PM
  2. MP3s and Browse
    By AndrewM16921 in forum New To Java
    Replies: 2
    Last Post: 08-13-2009, 04:45 AM
  3. Replies: 1
    Last Post: 11-28-2008, 06:27 PM
  4. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 05:40 PM
  5. Replies: 0
    Last Post: 01-22-2008, 11:05 AM

Posting Permissions

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