Problem with JFileChooser

I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

Similar Messages

  • Anyone had problems with jFilechooser?

    I have problems with JFilechooser freezes when invoking returnVal = chooser.showDialog(this, "Select");
    For some reason it freezes the entire program, allthough sometimes (rarely), it doesn't freeze.
    Are there currently any problems with JFileChooser? I have not had any problems when embedding it in a window - only when using it on its own with JFileChooser chooser = new JFileChooser();
    Regards / Daniel

    There was a bug with JFileChooser where it would be unnecessarily slow when the directory it was showing contained huge zip files on Windows. It seems like it had something to do with the Win32 API calls they were making actually looked into all of the zip file's entries even though it didn't need to. This was fixed back in Java 6 update 10. What Java version are you using?
    If that isn't your problem, you'll have to post an SSCCE demonstrating your problem to get any help.

  • Iam getting problem with Jfilechooser iam not getting networkneighbourhood

    Dear Sir,
    Iam doing a product for education portal for that we are using swing as frontend in that we are using Jfilechooser where ever we want but the problem is in filechooser iam getting the directories of the system(like C, D, E). But iam not getting the networkneighbourhood in that. Please any body can solve my problem i want to select networkneighbouhood. Ill be waiting for your reply.If apiece of code is there ill be very thankful.
    regards
    surya

    Unfortunately can't be done with JFileChooser, you would have to write your own version.
    See the bottom of this document
    http://java.sun.com/products/jfc/tsc/articles/merlin/windows/index.html
    Unfortunately the link that the text then leads you on to is broken.

  • Problem with JFileChooser and ImageIcon

    I'm trying to create an ImageIcon object from file selected in JFileChooser. The problem is that jfc.getSelectedFile().getAbsolutePath() returns a string with backslashes and the constructor of ImageIcon requires the string to have slashes. I`ve tried to create it via URL but it doesn't work as well...
    String lastUsedPath;
    URL imageURL;
    JFileChooser fc = new JFileChooser();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    int returnVal = fc.showDialog(frame,title);
    if(returnVal==JFileChooser.APPROVE_OPTION){                    
         lastUsedPath = fc.getSelectedFile().getAbsolutePath();
         imageURL = getClass().getResource(lastUsedPath);     //don't really get this but I copied it from Java Swing Tutorial          
    }else{
         return null;
    int curH, curW;            
    ImageIcon srcIcon = new ImageIcon(imageURL);                              
    curW = srcIcon.getIconWidth();
    curH = srcIcon.getIconHeight();If I use it this way imageURL is set to null.
    If I set the imageURL as 'fc.getSelectedFile().toURL()' the string is eg.: "file:/E:/file.jpg" instead of "E:/file.jpg". After that the ImageIcon is created but width and height return -1.
    If I try to create ImageIcon by 'new ImageIcon(lastUsedPath)' I get a not null object but the width & height of the ImageIcon is -1 as well.
    What do I have to do to be able to create an ImageIcon from file selected in JFileChooser? Why is this so hard and mind blowing?

    It still returns the ImageIcon object with width & height set to -1.
    EDIT:
    Got it finally:
    lastUsedPathForStupidImageIcon = fc.getSelectedFile().getPath();     
    img = ImageIO.read(new File(lastUsedPathForStupidImageIcon));
    curH = img.getHeight(this);
    curW = img.getWidth(this);The key was to use another String variable and hold the path instead of the absolute path
    Edited by: Beholder on Jan 17, 2010 1:35 PM

  • Problems with JFileChooser and Windows 2000 (can't see mydocuments contents

    Hi! I've an applet which has a JFileChooser component. In other Windows, I can select the MyDocuments folder and it goes there and list all the contents OK. But, in Windows 2000, when I go to MyDocuments, none of the contents is listed in the file chooser. I need to navigate through all the directories to get there (C:\documents and settings\user\my documents) and then, it shows its contents, but obviously, I don't want it to be this way because is difficult for the common user.
    Any idea of why is going on this?
    Thanks in advance!

    Hello, You need to use something like o=isp as the
    root DN, then o=yourorg.com goes beneath it.
    i.e.
    For the other questions on setup, just choose o=isp
    as base DN when you set up the directory server. When
    you run ims_dssetup.pl, choose o=internet as the DC
    tree base, then choose o=isp as the user/groups base
    suffix.
    When you are installing messaging server it will ask
    where to put the default organization, this is where
    you would choose o=abc.com, o=isp
    For more info on how this structure works please take
    a look at this link and it will all fit into place:
    http://docs.sun.com/source/816-6017-10/changes.htm#170
    8Alright, I got ims_dssetup to run successfully. But now when the ims 5.2 installation is about 50% done, I get the message:
    A serious problem occurred while installing the iPlanet Messaging Server Messaging SIE entry in LDAP (msg.cfgldap.sie.inf). It reported the following problem:
    The server configuration for the Messaging SIE entry in LDAP (msg.cfgldap.sie.inf) cannot be created.

  • Problem with JFileChooser when run using Netbeans

    I just want to state that I have NO problem writing the code that brings up this component. My problem is what happens when the JFileChooser component is loaded. My environment is Windows Vista, Java SE 1.6.0. -> Netbeans IDE 5.0. The code I use is as follows:
    public RegexParser()
    JFileChooser openfile = new JFileChooser();
    openfile.showOpenDialog(RegexParser.this);
    int returnVal = openfile.showOpenDialog(RegexParser.this);
    if (returnVal == JFileChooser.APPROVE_OPTION)
    //This code gets the path of the file and uses as a parameter to parse data.
    filename = openfile.getSelectedFile().getPath();
    openfile.setVisible(false);
    ParseData(filename);
    The problem is when I try to select an option from the combobox labeled "Look In:" Every directory I select which is not the root of the drive will display NO FILES even though there are files in that directory.
    Notice: I have also run the same code using the cmd.exe and it works fine. I have also looked at: http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html but have found nothing that has helped me.
    Can someone explain what is the problem? Is this a known bug in Netbeans? Is there any code that can be used as a workaround?

    Yes I copied the code to my machine and run it. The example program had problems when I executed using netbeans it had the problem.
    When I executed using Command Prompt there where no problems.

  • Lag problem with JFileChooser

    I have searched the archives and haven't found any useful information regarding the fact that creating a JFileChooser lags horribly on some systems...namely mine. I have tried running my own program and the FileChooserDemo on java versions 1.4.1_02, 1.4.1_06, 1.4.2_01-b06, and 1.5.0 beta and all of them have the INCREDIBLY slow lagging problem. I am running Win XP pro P3 800 386MB and it takes over 40 seconds to load the chooser. I have disabled all anti-virus software to no avail. I have run my program on a computer at my college which runs Win XP also and there it runs fine...so I am at a complete loss as to what could be wrong. If anyone has any insight into this problem please let me know!
    thanks

    Yeah...they talk a lot about theories of what the problem may be, but only offer a few solutions...none of which have helped me (loading the JFileChooser when app starts, and stopping anti-virus software). Thanks though.

  • A problem with jFileChooser

    I'm creating a GUI application in NetBeans, where I'm using jFileChooser object to select a file when a user clicks a button, the filechooser dialog appears and doesn't respond to the user's action but after closing the file chooser using the close button. When I click the button second time it works fine, what could be the problem. If possible, Please give me the code that does it.
    Thanks in advance

    In the future all swing related question should be posted in the swing forum.
    All you need to know about jfilechooser.
    http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html

  • Problems with JFileChooser

    I looked thru the bug database and forums but didn't see anything quite like this. I have JFileChooser that I use for a user to select an input test case (XML file) and optionally select an output directory. The trouble is, for some reason, the output directory text value is being corrupted, the last occurrence of the file.seperator is being dropped i.e. instead of getting c:\dir1\dir2\dir3, I am getting c:\dir1\dir2dir3. The code I use is shown below. Am I doing something stupid or is there something else going on? Cheers, Max
            smt.fcOutButton.addActionListener(new ActionListener()
                 public void actionPerformed(ActionEvent ae)
                                  JFileChooser fc = new JFileChooser();
                                  fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                                  fc.showOpenDialog(smt.frame);
                                  try
                                       String filename = fc.getSelectedFile().getPath();
                                       smt.outFileText.setText(filename);
                                       smt.outDir = fc.getSelectedFile().getParent() +
                                            fc.getSelectedFile().getName() +
                                            System.getProperty("file.separator");
                                       System.out.println(smt.outDir);
                                  catch (NullPointerException npe)
            });

    instead of System.getProperty("file.seperator")
    i use
    File.separator
    or
    File.separatorChar
    then I don't have to call the System.getProperty() method.
    have used it on Linux and Windows.

  • Problem with JFileChoosers

    I have a problem with JFileChooser.showOpenDialogBox(Component c). When I select a directory and click the Open button,the program goes wacky. Same is the case if I click Cancel button without selecting any file. How to solve this problem. I want the directory be opened and all subdirectories and files be shown just as in MS Word for example.

    Try and modify the following function:
         * Loads the FileChooser Object if not present.
         *@return Instance of File chooser
         private JFileChooser getFileChooser()
              if (mFlChooser == null)
                   mFlChooser = new JFileChooser();
                   mFlChooser.setFileFilter(
                        new javax.swing.filechooser.FileFilter()
                             public String getDescription()
                                  return sRes.getString("Text Documents (*.txt)");
                             * See Parent for Doc
                             *@param f See Parent for Doc
                             *@return See Parent for Doc
                             public boolean accept(File f)
                                  // Adapted
                                  if (f.isDirectory())
                                       return true;
                                  String extension = null;
                                  String s = f.getName();
                                  int i = s.lastIndexOf('.');
                                  if (i > 0 && i < s.length() - 1)
                                       extension = s.substring(i + 1).toLowerCase();
                                  if (extension != null)
                                       return extension.equals(".");
                                  return false;
              return mFlChooser;
         }

  • Problem with the JFileChooser

    Hello all,
    I'm having a small problem with the JFileChooser, the thing is whenever I click the cancel button in the dialog box a NullPointerException is thrown, so does anyone know wut is wrong?

    Either way, it's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • Problem with Image file

    Hi,
    Iam facing with one problem.I have one swing interface through which I can upload files(back end servlet programme).Now I can upload all types of file but problem with image file it uploading perfectly that means size of the uploaded file is ok but its format damaged.It can not be open.My backend servlet programme is ok coz i tested it with html form it is working perfectly.Problem with swing interface.Plz guide me where I done a mistake.Below r my codes:-
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
         Button=new JButton(Upload);
         Button.setToolTipText("Upload");
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
              int returnVal = fc.showOpenDialog(ActionDemo4.this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fc.getSelectedFile();
    String aa=file.getAbsolutePath();
              textArea3.append(aa);
                   textArea2.append("Local URL:");
    long l=file.length();
              try
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff);
              String str1=textArea10.getText();
    url = new URL ("http://127.0.0.1:7001/servletUpload?x="+str1);
         urlConn = url.openConnection();
         urlConn.setDoInput (true);
         urlConn.setDoOutput (true);
         urlConn.setUseCaches (false);
         urlConn.setRequestProperty("Content-Type","multipart/form-data;boundry=-----------------------------7d11e410e500f2");
         printout = new DataOutputStream (urlConn.getOutputStream ());
    String content ="-----------------------------7d11e410e500f2\r\n"+"Content-Disposition: form-data;"+"name=\"upload\"; filename=\""+aa+"\"\r\n"+"Content-Type: application/octet-strem\r\n\r\n\r\n"+conffile+"-----------------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);
    printout.flush ();
    printout.close ();
    Best Regards
    Bikash

    The errors are here:
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff); (conffile is a String object containing the image)
    and here:
    String content ="-----------------------------7d11e410e500f2\r\n"+"Con
    ent-Disposition: form-data;"+"name=\"upload\";
    filename=\""+aa+"\"\r\n"+"Content-Type:
    application/octet-strem\r\n\r\n\r\n"+conffile+"--------
    --------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);conffie is sent to the server but
    it's non possible to treat binary data as String!
    Image files must be sent as byte[] NOT as String ......

  • 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

  • Facing problem in JFileChooser setSelectedFile

    Hi All,
    Am facing problem in JFileChooser's setSelectedFile.
    While trying to save the file I give a default file name which may contain "/" also.When I pass the File Object with the name(eg AC/B_XYZ_123) to the JFileChooser's setSelectedFile it is displaying the file name in the dialog as B_XYZ_1234 and it is not allowing me to browse through the directories.The file dialog is showing the default director if i try to move to some other directory for saving the file it is not moving insted it is again showing the same directory.
    the following lines of statements am using in my code.
    File defaultFile = new File("AS/B_FTies2107_0138.csv");
    fileChooser.setSelectedFile(defaultFile);
    if file doesnt contain any "/" then it works fine, i could able to browe through the directories and save the file,problem occurs only when the file name contains "/"
    in my dialog it is displaying the file name as "B_FTies2107_0138.csv"
    can any one help me in solving this problem.
    Thanks & Regards
    N.V.N.GopiKrishna

    It's because / is used to denote a new directory. This originated from *NIX type systems but also now works on Windows. Your best bet is to use a different character, maybe a hyphen.                                                                                                                                                                                                                                                                                                                                                                           

  • Error compiling with JFileChooser

    Hi all,
    I'm having a problem with some code not compiling. I'm using the linux blackdown sdk on FreeBSD. I have created a new class to test this problem and I get the same response I was getting in my main application. The code is as follows:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame {
            JFileChooser chooser = new JFileChooser(".");
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }The error message that I am getting is as follows:
    $ javac Test.java
    Test.java:9: <identifier> expected
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    ^
    Test.java:9: package chooser does not exist
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    ^
    2 errors
    I can't see what I'm doing wrong here. I've definitely created chooser as a new JFileChooser object.
    Any help would be much appreciated!
    Thanks,

    you can't call one of your object's methods outside of a method/constructor body. Try this:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test extends JFrame {
         JFileChooser chooser;
         public Test() {
              super("Test");
              chooser = new JFileChooser(".");
              chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    Happy Birthday to Me.

Maybe you are looking for

  • Bought a used HP Coler Laserjet 4700N and don't know how to hook up.

    I just bought a HP Color Laserjet 4700n printer from a place that just sold out.  I didn't any cords to connect it to my Del Dimensions E520 couputer.   I am just a computer user and connecting this printer sounds a bit complicated.  I didn't get any

  • Integrating Active Directory LDAP in OBIEE 11g

    Hi All, I Have Configured Active Directory LDAP in OBIEE. Steps i have Followed are, 1) configured Active Directory in providers under Scurity Releam. 2) Restarted BI Services to Load the Ldap Users. 3) login to the EM under bifoundation domain selec

  • Re: Regarding HR ABAP

    Hai Experts, i need to know in which infotype company code is stored in HR Organizational management,i.e in HRP tables. can u please tell me the solution as soon as possible. With Regards, R.Dhineshraj.

  • HT1491 I have an account and when I enter my password they want me to answer questions

    I have a account all ready with iTunes and when I sign in they want me to answer security questions I have never set that up

  • Remove parent Keyword without losing the children

    As an example I set up a keyword set where I had company > department > PR or maintenance or IT etc. I don't really need to have dept in there can I remove it without losing the department names which I do want I have run into this and had just rewri