Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JFileChooser setting directory

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JFileChooser setting directory

    Hello all,

    I have created a jfilechooser and used the setCurrentDirectory method to set the directory which is opened when the filechooser is called. What I want though is for the directory I set to be the only directory available. My code is below :

    JFileChooser fileChooser = new JFileChooser();
                fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                fileChooser.setCurrentDirectory(new File(".\\Saved"));
     
     
                fileChooser.setAcceptAllFileFilterUsed(false);
                SaveFileFilter filter = new SaveFileFilter();
                fileChooser.setFileFilter(filter);
                fileChooser.addChoosableFileFilter(filter);
     
     
                fileChooser.showOpenDialog(this);

    I've done the same for the filefilters I've set. Is there any way to set it so only one directory is shown?

    Thanks in advance


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,699
    Thanks
    25
    Thanked 334 Times in 310 Posts

    Default Re: JFileChooser setting directory

    I don't have much time to do some researching, but I found this while googling:
    java - How do I restrict JFileChooser to a directory? - Stack Overflow

    There might also be something useful in one of these tutorials:
    JFileChooser : JFileChooserSwingJava Tutorial

    Sorry I can't provide any direct information.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: JFileChooser setting directory

    Moved thread to - AWT / Java Swing - Java Programming Forums
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. How to add file extension to JFileChooser.showSaveDialog() ?
    By camboy8 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 25th, 2012, 10:23 AM
  2. Can't get it to save stuff with JFileChooser
    By javapenguin in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 11th, 2010, 05:13 AM
  3. Using JFileChooser to open and display an image
    By JavaN0ob in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 31st, 2010, 07:01 PM
  4. JFileChooser
    By FretDancer69 in forum AWT / Java Swing
    Replies: 2
    Last Post: February 3rd, 2010, 06:35 AM
  5. Replies: 2
    Last Post: March 6th, 2009, 03:00 PM