Problem using JFileChooser to select a destination directory

If you set JFileChooser to DIRECTORIES_ONLY, a user has to single click on the desired directory and click on the approveButton. This works just fine - you get the user's desired directory using getSelectedFile().
e.g. /home/joeuser/docs
But if the user double-clicks on their desired directory (a common user practice), the directory is opened AND the directory name is stuck in the File Name: field. If they now click on the approveButton, the returned selected directory is the user's desired directory PLUS the name of the directory again. Not what the user intended.
e.g. /home/joeuser/docs/docs
Now, when you keep the File Name: field from being filled in when the user double-clicks on a directory, you have encounter another problem. The approveButton will not activate unless there is something in the File Name: field!
Does anybody have a solution for the approveButton working with an empty File Name: field?
Thanks,
Scott

I had the same problem. Gave up with JFileChooser and made a directory chooser that only display the diectory structure in a JTree and no file stuff at all.
Source: http://www.msticky.freeserve.co.uk/JDialog_directoryChooser.java
to use it; String selectedDirPath=JDialog_directoryChooser.choose(stringTitle, stringInitialSelectedPath)
returns the selected directory path or null if none selected.
To make it work alone you'll need to remove my RRException class. If you want to see it in use first download noname.jar from http://www.msticky.freeserve.co.uk
ps. my site needs testing
thanks, sticky

Similar Messages

  • Using JFileChooser to select directory only

    Hi. I am using JFileChooser to let the user to select the directory to save some files into the user-selected directory. I set the JFileChooser to show only directory and not files. Below show part of my code:
    private JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(true);
    chooser.setMultiSelectionEnabled(false);
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
         chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    int state = chooser.showDialog(frame, "Select Directory");
    if (state == JFileChooser.APPROVE_OPTION )
    file = chooser.getCurrentDirectory();
    However, the File reference that i get is not the user-selected directory. Please help.
    Thank you.

    Hi,
    i found that if user writes in the text field of save dialog name of the file(but application needs directory), getCurrentDirectory() returns correct directory. but if user chooses directory, getCurrentDirectory() returns parent directory but getSelectedFile() returns correct one, so i suggest something like this(it's nasty but it works [i hope;])
    JFileChooser dirChooser = new JFileChooser("");
    dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (dirChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
    java.io.File curDir = dirChooser.getSelectedFile().isDirectory()?dirChooser.getSelectedFile():dirChooser.getCurrentDirectory();

  • Problem using JFileChooser

    Hi,
    I am encoutering a strange error dialog, javaw.exe No-Disk dialog box with this message "There is no disk in the drive. please insert a disk in drive A" when using JFileChooser.
    I have been referring to some forums and understood this is a bug. But most encountered this when they are using it with Java Web Service or some web application.
    I have Windows 2000 and mine is a java application. I have tried a workaround with WindowsAltFileSystemView but that does work with Windows 2000.
    So is there any workaround..help needed.
    thanks.

    If you do not do so already, try setting a starting point for your JFileChooser.
    JFileChooser chooser = new javax.swing.JFileChooser();
    chooser.setCurrentDirectory( someDirectory );The "someDirestory" could be any directory you want or need depending on Platform independance or not.
    regards,
    jarshe

  • Problems using JFileChooser

    I'm trying to create a multiple file upload, where is possible to select several files, but i'm getting stuck because i can't get pass the JAVA Permissions.
    This is my applet:
    [http://andre.paraiso.googlepages.com/Browser.zip|http://andre.paraiso.googlepages.com/Browser.zip]
    I'm using a JFileChooser to get the files that are selected to upload, but the VM don't let me run the applet.
    Can anyone explain me how to get around this problem, the problem is that i need to run this applet in several machines that is not the possibility to change the java.policy
    My thanks in advance.
    André Paraíso

    OK i need to sign my applet, i have been looking and the only way i find to sign an applet needs payment to validate the certificate.
    Is there any way to sign the applet whiteout the need for a payment???
    The links that where posted are out of date, they exist but the important subject to whee they link don't exist any more.
    Thanks. . .

  • Problem using CASE within SELECT in a standard REPORT region

    I'm trying to do a CASE-oriented SELECT within a standard REPORT region and the parser is rejecting the SQL statement.
    The code I'm using is the following:
    SELECT
    CASE
    WHEN INSTR(citation, '@') > 0 THEN
    SUBSTR(citation, 1, INSTR(citation, '@')-1)
    || ':'
    || SUBSTR(citation, INSTR(citation, '@')+1,
    LENGTH(citation) - INSTR(citation, '@'))
    ELSE citation
    END
    FROM citation
    WHERE obj_table_cd = 'FI'
    AND obj_id = :P41_FIND_ID
    ORDER BY CITATION
    The parser says the (case .... ) is invalid, use column alias. The query works correctly when using SQL_Developer and SQL*PLUS.
    My intention is to replace an '@' with ':' within the citation text. The standard citation format should have a colon, but this causes problems with AppExpress, hence the substitution situation.
    Any insights on this or on another way to achieve the purpose?
    Thanks,
    George

    George,
    You should give a column alias after the END of the case statement:
    SELECT
    CASE
    WHEN INSTR(citation, '@') > 0 THEN
    SUBSTR(citation, 1, INSTR(citation, '@')-1)
    || ':'
    || SUBSTR(citation, INSTR(citation, '@')+1,
    LENGTH(citation) - INSTR(citation, '@'))
    ELSE citation
    END citation_col
    FROM citation
    WHERE obj_table_cd = 'FI'
    AND obj_id = :P41_FIND_ID
    ORDER BY CITATIONSam

  • How to use JFileChooser to select only hard drive?

    I am doing CD update. I am using a component called "JFileChooser". I use this component to let user choose a Hard Drive or Floopy. When I try this component, and if I choose a hard drive and a folder/file, it works. If I only choose hard drive, it will return "My Documents"??? I cann't get hard drive. How to set up JFileChooser so user only choose hard drive and it will return this hard drive. Thanks for help.
    Gary

    Easiest (and maybe most portable) way is to have a specific file in your root directory of the CDROM. You could use java.io.File.listRoots() to get all drives and then pick the one that has your file.
    This will enable the user to copy the CDROM to a hard drive (easier for testing also) or mount a remote CDROM.

  • Get the file directory/location using JFileChooser

    Dear,
    How to get the file directory and it location with using JFilechooser after select the indicate file?
    Thanks

    There is an example at the top of JFileChooser's doc.
    http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFileChooser.html

  • Opening a specific directory using JFileChooser.

    Iam using JFIleChooser to select a file is there any way that i the dialog opens at a particular directory say...c:\gallery\imagee...the default dialog opens @ MyDocuments Folder.

    Read the API documentation of the class, especially coustructor section.

  • Using jfilechooser

    hi all,
    how to use jfilechooser to select a file available in another computer of my LAN.
    i used setFileSelectionMode(JFileChooser.FILES_ONLY);with this statement, if i give 'c:' or any local/mapped drive names in text box, it lists the files properly and i can choose the file.
    but, if i give the IP address of another system, i.e like '\\192.168.0.243', it simply accepts this (\\192.168.0.243) as filename and closes the file chooser dialog. if i type the ip address, the file chooser should list the shared drives in that system.  how to do this?
    i tried java.awt.filedialog, but it does this, but supports only single file selection
    thanking you.

    rnoack wrote:
    1) i don't find it amusing that we are even having this conversation, it is immature and i have tried to end it twice now but you always seem to want to have the last word (which would be fine with me if it didn't negatively reflect on my intentions or values)The "problem" in this case is that is that Darryl.Burke is correct. Cross-posting is really rude, it means that you don't care about the time that people spend answering questions. Most frequenst posters at all forums and mailing lists will tell you that.
    Cross-posting and not saying in the post that you are cross-posting is even worse. (Cross-posts are often removed from these forums).
    >
    2) i never did, and never will think that i can tell you want to do or not to do. i was merely offering advice which i feel and will continue to feel regardless of your beliefs is for the best of all related communities.Note that Darryl is a moderator and tried to tell you that you shouldn't cross-post. Most frequent posters would have done that if they had found out that you were cross-posting. The only mistake that Darryl did is that he thought that you were going to listen to his advice even if he didn't make that specific post as a moderator.
    Kaj
    Ps. I also blocked an abusive post.

  • JFileChooser in Applet keeps focus after selection of a directory

    I have spent several days on the following issue, but haven't found any solution so far...
    When I open a JFileChooser out of an Applet and select a Directory, the FileChooser closes as expected, but a text field located on the main applet pane cannot be selected any more (the mouse pointer goes to "text cursor" style when hovering over it, but the text field does not get the focus when clicked). Strangely, the other button on the same pane still reacts to mouse clicks. This happens only when I select a directory, but not when I choose a file. Also, it does not happen, when I click "Cancel" instead of "Open". Furthermore, the problem occurs only using the Firefox plugin, not in the AppletViewer. I even tried to remove the text field from the root pane and add a new one after the file chooser execution, but still it won't regain focus.
    Here's the stripped-down code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class TestApplet extends JApplet {
        private static final long serialVersionUID = 1L;
        @Override
        public void init() {
            final JPanel rootPanel = new JPanel();
            rootPanel.setLayout(new BorderLayout());
            getContentPane().add(rootPanel);
            final JButton fileChooserButton = new JButton("Start");
            fileChooserButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.setAcceptAllFileFilterUsed(false);
                    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                    fc.setMultiSelectionEnabled(false);
                    fc.showOpenDialog(rootPanel);
            JTextField textField = new JTextField();
            rootPanel.add(fileChooserButton, BorderLayout.CENTER);
            rootPanel.add(textField, BorderLayout.SOUTH);
    }And this is the applet.html:
    <applet code="TestApplet.class" codebase="file://home/administrator/workspace/Test/bin" width=100 height=50></applet> This concerns: Ubuntu 9.04 / Firefox 3.6.9 / JVM 1.6.0_20
    Any help or ideas for a workaround would be much appreciated...

    AndrewThompson64 wrote:
    JWS was available as a separate download since Java 1.2. It became bundled with the JRE around 1.4.2, not sure of the micro-version, but it was in the 1.4 era. 1.4 has been relegated to the 'obsolete' pile now, so I think you are safe expecting the end user to be prepared to update to 1.5+ if needed.You don't know my grandma: she isn't prepared to anything, but she wants things to just work ;-)
    For ensuring the user has a minimum of 1.5, see the [Java&#153; Rich Internet Applications Deployment Advice|http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html] for details of the deployJava.js script. It is useful for both applets and apps. deployed using JWS.
    Yes, I already use this script for my Applet, but I hadn't realized that it worked for JWS as well.
    Do you mean like a corporate intranet?Exactly. Another example could be centrally managed laptops connecting over Internet to your application (like the traveling salesman connecting to his task planner)
    ... Can you do a search of the bug DB and if nothing shows up, submit one? The only chance these things will get fixed is if they are reported.I agree with you on that question and I've already had a look (didn't find anything so far)
    Embedded applets are a PITA. I wouldn't disagree, but again, if you want to bring a rich client to the masses, sometimes that's the way to do it (unless you go for ActiveX, which is definitely not an option for me). Anyway, I'll give JWS a try.. and then I'll ask the customer help desk if it was a good idea...
    For example, is there any programmatic way to determine if the embedded applet is not acting as expected? If so, monitor that and on detection, pop a dialog to the user explaining the situation and offering the free floating version from a button click.Well, I have to think a bit more about this. Probably I will just to check if the text field gets the focus after a mouse click, by adding some kind of test inside a MouseListener. If it doesn't get the focus, I would be quite sure that there's a problem... I'll look into this.
    On the other hand, to work around the whole problem, I have found some Open Source Directory Chooser (http://sourceforge.net/projects/jfolderchooser), which looks nice at a first glance, but I didn't have the time to go into it in more detail. I'll just quote you here:
    I cannot say if this will fix the problem. Or perhaps it will fix the problem in that browser/JRE combo., but break it in another. ;)Words full of truth :)

  • JFileChooser Multiple selection not working on Mac using apple, command key

    I am using Java 1.4 webstart on Mac machine.
    The code is :
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(2);
    fileChooser.setMultiSelectionEnabled(true);
    Once the File dialog opens I have problems in selecting random multiple files. Apple key or command key is used for random selection on Mac. When using either of these keys multiple selection is not possible. Whereas I am able to select files using the shift key by which row selection is possible.
    If this is not a bug and some code changes are to be done it would be fine if somebody can help me out in this.
    If this is a bug in Java 1.4 and is this fixed in Java 1.5?

    All EIDE / ATA (Parallel) devices (drives, opticals) allowed for two such drives or devices on one bus. The old style was "master" and "Slave" but CS is a "smart" approach, however, the master or only device must be on the end position. Also, the end connector will be black, the middle (slave) is gray.
    Eject sends signal to master
    To eject the "slave" device you use a modifier key.

  • JFileChooser Multiple selection not working on Mac using apple key

    I am using Java 1.4 webstart on Mac machine.
    The code is :
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(2);
    fileChooser.setMultiSelectionEnabled(true);
    Once the File dialog opens I have problems in selecting random multiple files. Apple key is used for random selection on Mac. When using the apple key multiple selection is not possible. Whereas I am able to select files using the command key by which row selection is possible.
    If this is not a bug and some code changes are to be done it would be fine if somebody can help me out in this.
    If this is a bug in Java 1.4 and is this fixed in Java 1.5?

    All EIDE / ATA (Parallel) devices (drives, opticals) allowed for two such drives or devices on one bus. The old style was "master" and "Slave" but CS is a "smart" approach, however, the master or only device must be on the end position. Also, the end connector will be black, the middle (slave) is gray.
    Eject sends signal to master
    To eject the "slave" device you use a modifier key.

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • How to get the file path of selected file using JFileChooser

    Hi All,
    I am trying to store the file on my FTP server after selecting the file from the user workstation using JFileChooser. But I am not able to write the file on FTP server or on user local machine where application is running. I am new to this FTP server coding. Can anyone help me in this.
    This is the code I wrote on button click user will able to select the file:
    String filename1;
    File file;
    JFileChooser fc = new JFileChooser();
    fc.showOpenDialog(this);
    file = fc.getSelectedFile();
    filename1 = file.getPath();
    txtFilePath.setText(filename1);
    Below is the code to write the file on my local machine first:
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    outFile.write();
    outFile.flush( );
    outFile.close( );
    Any help will be greatly appriciated

    rp0428 wrote:
    >
    BufferedWriter outFile = new BufferedWriter( fileName ) );
    >
    There is NOTHING named 'fileName' in any of the code you posted so that code can't possibly compile let alone actually run.
    How can anyone help you if you won't post the actual code you are using?Its just a random snippet of other code that is totally irrelevant to this thread if you ask me.

  • Problems using Oracle Directory

    Hi all
    I have the following problem using 9i: I would like to use oracle internet directory to register my db's. I am currently reading the online handbooks and found a section that says to start the directory by using the 'oidmon' and 'oidctl' commands. The problem is that I cannot find these tools anywhere on the server, altough i am pretty sure i intalled anything important. is this a separate product? I thought it was included in 9i 9.2?
    Anyone?
    Cheers,
    Michael

    Hi.
    Hmm, your shared lib path appears to be ok. What version of Solaris are you running? Also what JDK version are you using (I'll assume you are using the one that installed with WLS)?
    You might also try posting this to the weblogic.developer.interest.jdbc newsgroup.
    Thanks,
    Michael
    Alex wrote:
    Hi,
    Please help. While trying to do a dbping, I get the following error:
    [root@hkodsdb01 SMEloan]# java -Djava.library.path=/export/home/greenwood/bea/wlserver6.0/lib/solaris:/export/home/greenwood/bea/wlserver6.0/lib/solaris/oci817_8:/u01/oracle/product/817/lib utils.dbping ORACLE oracle smeloan 192.168.1.252
    Starting Loading jDriver/Oracle .....
    Error encountered:
    java.sql.SQLException: System.loadLibrary threw java.lang.UnsatisfiedLinkError with the message '/export/home/greenwood/bea/wlserver6.0/lib/solaris/oci817_8/libweblogicoci37.so: ld.so.1: /greenwood/bea/jdk131/jre/bin/../bin/sparc/native_threads/java: fatal: libclntsh.so.8.0: open failed: No such file or directory'.
    at weblogic.jdbcbase.oci.Driver.loadLibraryIfNeeded(Driver.java:202)
    at weblogic.jdbcbase.oci.Driver.connect(Driver.java:57)
    at java.sql.DriverManager.getConnection(DriverManager.java:517)
    at java.sql.DriverManager.getConnection(DriverManager.java:146)
    at utils.dbping.main(dbping.java:167)
    The required file is under the Oracle directory specified. Also, I am having some problems with using the LD_LIBRARY_PATH for my shared library files. The command won't work with LD_LIBRARY_PATH and I must use the -Djava.library.path parameter. Any thoughts and suggestions?
    Thanks so much for your help in advance.
    Alex--
    Michael Young
    Developer Relations Engineer
    BEA Support

Maybe you are looking for

  • How to show more than one record at a form-like style report?

    Hi All, I developed a form-like style report I want it to show more than one record at once (At the same page) I tried that by setting the value to "Maximum records per page" property for the repeating frame to 10 but when I close the property palete

  • Error reporting in BAPI_BILLINGDOC_CREATEMULTIPLE

    Hi there, I've adapted parameters via customizing to take an orders as reference documents when creating invoices.  The thing is that when I create invoices using deliveries with VF01 I can figure out that I did it wrong cause I get an error message

  • Pro  cs3 crashing constantly with extra audio

    As described above; when putting another audio wavefile on the timeline [track 2] pro cs3 starts crashing [pc boots!] when moving along the timeline and using the ripple edit tool. Project doesn't want to open again afterwards... I use aspect hd to e

  • MacBook Pro and T2I

    Hi there, I recently got accepted into film school and am looking to buy a Macbook Pro for film editing. My current camera is the Rebel T2i/550D. I'm looking to run Final Cut Studio (whatever the newest version is), however, being a student, my budge

  • HT4847 how do i store my photos on i cloud?

    How do I store my photos on I Cloud?