Results 1 to 5 of 5
  1. #1
    captainpirate is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default JFileChooser : Files and Directories

    I have a MenuItem name openMenuItem and its actionPerformed method is below :


    private void openMenuItemActionPerformed(java.awt.event.ActionE vent evt) {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(choosertitle);
    chooser.setFileSelectionMode(JFileChooser.FILES_AN D_DIRECTORIES);
    javax.swing.filechooser.FileFilter filter1 = new javax.swing.filechooser.FileFilter() {
    public boolean accept(File file) {
    String filename = file.getName();
    return filename.endsWith(".mp3");
    }

    public String getDescription() {
    return "*.mp3";
    }
    };

    chooser.addChoosableFileFilter(filter1);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
    System.out.println(chooser.getSelectedFile());
    } else {
    System.out.println("No Selection ");
    }
    }

    what i want is that i want to allow the user to select either a file or a directory. And if the user select a file just use the directory where that file is located.

    Also i want double click to open the direcory.
    How can i do these ?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: JFileChooser : Files and Directories

    Look at the JFileChooser class and see what methods is has that can be of use to you.

  3. #3
    captainpirate is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default Re: JFileChooser : Files and Directories

    I tried to look it but didn't help.
    I am newbie to it. I am looking for concrete answer.
    @Norm thanx for your reply.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: JFileChooser : Files and Directories

    Use Search or Google for sample code.

    What did you try?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: JFileChooser : Files and Directories

    Moved from 'New to Java'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Merging PDF Files using PDFBox in Sub/Directories
    By blivori in forum New To Java
    Replies: 1
    Last Post: 07-26-2011, 07:06 PM
  2. Replies: 1
    Last Post: 07-07-2011, 10:04 PM
  3. Searching directories for folders and .txt files
    By XDrew574X in forum New To Java
    Replies: 1
    Last Post: 03-29-2011, 10:41 PM
  4. Save files in directories
    By Tota in forum New To Java
    Replies: 2
    Last Post: 09-02-2010, 03:49 PM
  5. List of files and directories.
    By artemff in forum CLDC and MIDP
    Replies: 6
    Last Post: 01-02-2010, 05:06 PM

Tags for this Thread

Posting Permissions

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