JFileChooser: display is emply or imcomplete

Dear All,
I have a problem in JFileChooser:
1. Some folders are not empty, but after using
JFileChooser,the display become empty and the folders can only display part of all files?
2. When JFileChooser is started, not scroll bar ?
Does anybody can give me a hand?
Thank you.
Kevin

Remove the following line from you code wherever it appears (twice):
fileChooser.setVisible(false);Once you click on the ApproveButton or the CancelButton then it is going to "hide." There is no need to call the setVisible(false) method.

Similar Messages

  • JFileChooser Displays Garbage Icons for Files in 1.4.2-02

    Since switching from 1.3.1 to 1.4.2-02 I no longer get meaningful icons displayed beside file names by JFileChooser. What it is displaying do not look like anything meaningful. I suspect it is just grabbing some random chunk of memory and interpreting it as an icon. In 1.3.1 I got a folder icon for directories and a dog-eared piece of paper for files. I have not changed any of the code here, except to fix a bug where I was passing an invalid object (not a Component) to showOpenDialog, and the problem occurs both before and after that change. I appreciate that I can create a FileView to display whatever icons I want, but I do not understand why the default is garbage.
         JFileChooser chooser;
         String     directory     = parent.getProperty("directory", "");
         if (directory != "")
         chooser = new JFileChooser(directory);
         else
         chooser = new JFileChooser();
         // select only Text and Excel files, but permit multiples to be chosen
         chooser.addChoosableFileFilter(new TxtFileFilter());
         chooser.setFileFilter(new XlsFileFilter());
         chooser.setMultiSelectionEnabled(true);
         // display the dialog and wait for a response
         int option = chooser.showOpenDialog(desk);

    I have since determined that the problem is in FileSystemView.getSystemIcon, which returns a garbage icon on my system.

  • JFileChooser displays annoying "Drive A" message

    When I use JFileChooser's showOpenDialog() method with JWS, my app displays a dialog box that says:
    "There is no disk in the drive. Please insert a disk into drive A:"
    I've tried setting a current directory and I still get the message. How do I get rid of this message?

    This is a known bug:
    http://developer.java.sun.com/developer/bugParade/bugs/4458949.html
    Please vote for it to be fixed!

  • JFileChooser displays garbage file icons

    When running JFileChooser on Win98 with the system look and feel set I get the same garbage icon for every file. I cannot find this in the bug database. I tried submitting a bug report but there seems to be a bug in the bug report web page as it complained that I had omitted essential data when I had not.

    You should report it here
    http://developers.sun.com/contact/index.jsp

  • How can JFileChooser display custom ShellFolders ?

    The windows flavor of the JFileChooser UI has a nice left column with ShellFolder entries.
    How can one extend this list to add one's own places like "My workgroup's common place"
    or "My Shared folder" ?
    I've tried to implement a decorator for the FileSystemView, but is doesn't really help and
    has synchronization problems (getRoots() has to be fully operational on the JFileChooser creation),
    is there a way to force a FileSystemView rescan for new folders ?

    Yup, possible using system variables that can track time and conditional advanced actions.

  • JFileChooser does not display Korean files

    I have an application that uses JFileChooser to select some files. The application is bundled with English version of JRE 1.6.0_06. On Korean Windows 2003 the application displays files with filenames in Korean and allows them to be chosen. However on Korean Solaris 10, it does not even display the files? Anyone have an idea on why there is this discrepancy?
    I assume that the file with the Korean filename created on Korean Windows 2003 got created with the MS949 encoding for the filename. Similarly I assumed that the file with the Korean filename created on Korean Solaris 10 got created with UTF-8 encoding because that's the encoding set on Korean Solaris when I log in (its not set to EUC-KR). So how do I get the files to display and allow to be chosen on Korean Solaris?
    Thanks,
    Kartik
    P. S. I have the same problem with filenames in Japanese - on a Japanese Windows 2003 server the JFileChooser displays the files while on a Japanese Solaris 10 box, the JFileChooser does not display the files.

    Hi,
    I am trying to pick up data from an excel sheet and insert them into a database. However, once updated, they end up with '?' values.
    I have tried to make font.properties.ja as the default font.properties file, which failed to display Japanese characters.
    Any suggestions?
    This is a part of my code:
    String sJIS = "";
    sJIS = new String(cell1.getStringCellValue().getBytes("8859_1"), "JISAutoDetect");
    String sUTF = "";
    sUTF = new String(cell1.getStringCellValue().getBytes(), "UTF-16");
    System.out.println("sUTF" + sUTF + " " + "sJIS" + sJIS);
    Thanks,

  • How to setToolTipText for a file in jfilechooser?

    I want to set tooltip text for a file in jfilechooser for getting its detail to user without selecting a file as it is in windows explorer(e.g for file size,date modified).
    Since jfilechooser does not give directly reference to a file without clicking the file.
    As i have found after googling that jfilechooser displays file in JList.
    So here is the code that get file in JFileChooser
    private Component findJList(Component comp) {
        if (comp.getClass() == JList.class) return comp;
        if (comp instanceof Container) {
            Component[] components = ((Container)comp).getComponents();
            for(int i = 0; i < components.length; i++) {
                Component child = findJList(components);
    if (child != null) return child;
    return null;
    where in findJList jFileChooser object is passed
    So i wan't to know is there any way so that the child being a file will be able to show tooltip for displaying file size or file details or any thing about File.
    Please give me any solution.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Silly me!
    The simple fact that the URL isn't null, means the file exists. No need to explicitly check it again.
    (Unless I'm missing something here?)

  • Prob. w/ JFileChooser in 1.4.x on Win. w/ CDF files

    I have an application which deals with files named with a .cdf extension. These files are NOT actually MS Channel Definition Files. With Java 1.1, 1.2, and 1.3, JFileChooser displayed my CDF files as files and allowed them to be choosen. With Java 1.4.0 and 1.4.1 FCS on Windows 2000 (problem doesn't exist on Solaris 8), JFileChooser displays them as empty directories. This prevents them from being selectable to be opened by the application. The problem is easy to reproduce with the FileChooserDemo from the Swing tutorial
    http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html
    Simply download and compile the code. Then create an empty file named test.cdf. Under Java 1.4.0, the file will have to be in a directory other than the current working directory of the application. Under Java 1.4.1 the problem occurs even when the file is in the cwd. java.io.File correctly identifies the file as a file (isFile() == true && isDirectory() == false).
    Is this new JFileChooser behavior the intended behavior? If so, how can I customize JFileChooser to restore the previous behavior in my applications? Thanks.
    Bernie

    The best workaround might be to provide a new FileView object
    which delegates to the default one. See example below.
    (Sorry for the tardy response.)
    Leif Samuelsson
    The Swing Team, Java Software
    Sun Microsystems, Inc.
    import java.io.File;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import javax.swing.plaf.*;
    public class CDF {
        public static void main(String[] args) throws Exception {
         JFileChooser fc = new JFileChooser();
         final FileView fv = ((FileChooserUI)fc.getUI()).getFileView(fc);
         fc.setFileView(new FileView() {
             File plainFile = new File("dummy");
             public String getName(File f) {
              return fv.getName(f);
             public String getDescription(File f) {
              if (f.getName().endsWith(".cdf")) {
                  return f.getName();
              } else {
                  return fv.getDescription(f);
             public String getTypeDescription(File f) {
              if (f.getName().endsWith(".cdf")) {
                  return fv.getTypeDescription(plainFile);
              } else {
                  return fv.getTypeDescription(f);
             public Icon getIcon(File f) {
              if (f.getName().endsWith(".cdf")) {
                  return fv.getIcon(plainFile);
              } else {
                  return fv.getIcon(f);
             public Boolean isTraversable(File f) {
              if (f.getName().endsWith(".cdf")) {
                  return Boolean.FALSE;
              } else {
                  return fv.isTraversable(f);
         if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
             System.out.println("You selected: " + fc.getSelectedFile());
         System.exit(0);
    }

  • JFileChooser Details and List Button

    I need Help!!!!
    Can someone explain to me how to enable the 'Details' and the 'List' button for the JFileChooser Metal Look & Feel. If this is not possible can someone exactly explain to me how to dislpay the file size and the file modified date in the JFileChooser display window. I have been racking by brain trying to figure this out. I need to display this information in the JFileChooser Open dialog window along with the file name, once I get to this point I will then need to sort and display these files by the file modified date. Thanks in advance for any help that I will receive on this topic.

    Hi Thomas! :)
    Yes, the "Details" and "List" work great! :)
    It will also display the "Type" and "Attributes" of the files!
    I couldn't find a "sort" function, but there is a good looking "public void setDragEnabled(boolean b)" method! :)
    I use the beta version of jdk1.4 (b65), maybe in the official release there'll be a sort function..
    CUL8er,
    Nick.

  • Problem about JFileChooser

    I am using JFileChooser to allow user to select only .wav file. When JFileChooser displaying out, only files with .wav extension and folders are shown.
    When there is text in filename text field, JFileChooser can return, which is not i want. Only existed .wav file can return caller.... Any guys out there, know how to customize this?
    Thanks in advance.

    Disabling the Open button might not be easy. You could force selection of a filetype using a loop and FileExtensionFilter's accept (File file) method. This is a sample code snippet that repeats the loop until a text (*.txt) file is selected or Cancel is clicked:JFileChooser chooser = new JFileChooser ();
    chooser.setFileSelectionMode (JFileChooser.FILES_ONLY);
    chooser.setAcceptAllFileFilterUsed (false);
    FileNameExtensionFilter filter =
          new FileNameExtensionFilter ("Text File", "txt");
    chooser.setFileFilter (filter);
    int retVal;
    do {
       retVal = chooser.showOpenDialog (null);
    } while (retVal == JFileChooser.APPROVE_OPTION
          && !filter.accept (chooser.getSelectedFile ()));You can easily add a check that the selected file exists to the loop condition.
    db

  • Bug in JFileChooser (Java 1.6.0_03 running on Windows XP)?

    Hello All,
    I tried to display a JFileChooser dialog for file selection. It opens in the "My Documents" directory.
    This directory contained a big (400 megs) ZIP file.
    The JFileChooser dialog tooked a very long time to be displayed (I didn't selected this big zip file).
    If I remove the ZIP file, the JFIleChooser displays fast.
    I did the test with the JFileChooser demo from sun (http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html), and I find the same result.
    I think that's really a bug in the implementation of JFileChooser. Can you tell me if it is possible to let sun know this problem?
    Kind regards.
    Michael Hooreman

    JFileChooser has always had a problem with Windows XP's insistence on treating Zip files as folders. That's a stupid feature anyway, and I'm surprised JFileChooser doesn't automatically bypass it. You can disable the feature by running the following command: regsvr32 /u zipfldr Note that you'll be disabling the feature in Windows, not just in Java. You can re-enable it by running the same command without the /u.

  • Subclassing JFileChooser?

    Hi,
    I need to dulicate JFileChooser behavior in a local JFrame client.
    But I need to make the source of the Tree it displays TreeNodes persisted as EJBs in a remote server MySql database instead of letting JFIleChooser read the local client file drive directly.
    I.e. the tree that the JFileChooser displays will be persited as EJB's that represent TreeNodes. The TreeNodes have the psudo file and directory names, and each TreeNode will hold a reference to another EJB Object that persists the contents of the pusdo file.
    I hate the thought of trying to reporduce behavior such as the ablity to click on a name to rename it seems daunting.
    Is there anything in the swing api that would help?
    GLB

    you can hack the FileSystemView (you can set it in JFileChooser, or pass in it in the constructor). Although the FileSystemView usese File Objects, you can either subclass File and provide custom implementation, or just make up your own path, just don't call any of the methods on the file object and you should be fine. I've done this before to all zip and jar files to be traversial (act like a folder).

  • How to retrieve additional information about roots?

    Excuse me for my little english..
    I have used the method "listRoots" of java.io.File class for get drive list on my system (Windows).
    Now, I need to obtain the device type for each root (for example floppy, cd-rom , hard disk, etc.).
    Can I do this, without using native interface?
    thank you so much,
    roybart

    Heres some code that I have. This might be what your looking for. getSystemDisplayName will
    display what jfilechooser displays.
    int idx = 0;
    FileSystemView fs = FileSystemView.getFileSystemView ();
    File flist[] = File.listRoots();
    for (idx = 0; idx < flist.length; ++idx)
    System.out.println ("file: " + flist[idx].getAbsolutePath() + " - " + fs.getSystemDisplayName(flist[idx]));
    }

  • JFileChooser problem - it will not display

    I have read the tutorial on JFileChoosers and understand the basics, however, my application will simply not display a File Chooser. I select the menu option "open file" and the command prompt window just spews out dozens of garbage. The code is below if there are any FileChooser "Pros" out there. The FileChooser is selected for loading in the actioPerformed method. Thanks for any assistance.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.*;
    public class DissertationInterface extends JFrame implements ActionListener
         private JPanel onePanel, twoPanel, bottomPanel;
           private JButton quit,search;
           private JMenuBar TheMenu;
           private JMenu menu1, submenu;
         private JMenuItem menuItem1;
         private JFileChooser fc;          //FILE CHOOSER
           private BorderLayout layout;
           //Canvas that images should be drew on
           //drawTheImages Dti;
           //Instances of other classes
         //DatabaseComms2 db2 = new DatabaseComms2();
         //Configuration cF = new Configuration();
           public DissertationInterface()
                setTitle("Find My Pics - University Application") ;
                layout = new BorderLayout();          
                Container container = getContentPane();
                container.setLayout(layout);
                //Dti = new drawTheImages();
              //container.add(Dti);
                quit = new JButton("Quit");
                search = new JButton("Search");
                TheMenu = new JMenuBar();
                setJMenuBar(TheMenu);
                //FILE CHOOSER
                JFileChooser fc = new JFileChooser();     
                fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                //First menu option = "File";
                menu1 = new JMenu("File");
              TheMenu.add(menu1);
                //Add an option to the Menu Item
                menuItem1 = new JMenuItem("OPEN FILE",KeyEvent.VK_T);
            menuItem1.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_1, ActionEvent.ALT_MASK));
              menu1.add(menuItem1);
              menuItem1.addActionListener(this);          //action listener for Open file option
                //CREATE 3 PANELS
                onePanel = new JPanel();
                onePanel.setBackground(Color.blue);
                onePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 200, 400)) ;
                twoPanel = new JPanel();
                twoPanel.setBackground(Color.red);
                twoPanel.setLayout(new GridLayout(5,2,5,5));
                bottomPanel = new JPanel();
                bottomPanel.setBackground(Color.yellow);
                bottomPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
              //ADD COMPONENTS TO THE PANELS
                //Add the menu bar and it's items to twoPanel
              twoPanel.add(TheMenu, BorderLayout.NORTH);
              twoPanel.setAlignmentY(LEFT_ALIGNMENT);
                bottomPanel.add(quit);
                quit.addActionListener(this);          //action listener for button
                bottomPanel.add(search);
                search.addActionListener(this);          //action listener for button
                //ADD PANELS TO THE WINDOWS
                container.add(onePanel, BorderLayout.CENTER);
                container.add(twoPanel,BorderLayout.NORTH);            
                container.add(bottomPanel, BorderLayout.SOUTH);
                //setSize(350,350);
                setVisible(true);
              }//END OF CONSTRUCTOR
            public void leaveWindow()
                 this.dispose() ;
            public static void main(String args[])
            DissertationInterface DI = new DissertationInterface();
            DI.setVisible(true);
            //Display the window.
            DI.setSize(450, 260);
            DI.setVisible(true);
            DI.pack();
         }//End of main method
         protected void processWindowEvent(WindowEvent e)
                super.processWindowEvent(e);
                if(e.getID()== WindowEvent.WINDOW_CLOSING)
                      System.exit(0);
              }//End of processWindowEvent
    //method to resolve button clicks etc
    public void actionPerformed(ActionEvent e)
              //PROBLEM IS HERE !!!!!!! - why won't the file dialogue box open
              if(e.getActionCommand().equals("OPEN"))
                   int returnVal = fc.showOpenDialog(DissertationInterface.this);
                 else if(e.getActionCommand().equals("Quit"))
                      //closeDialog();
                      System.out.println("User interface exited");
                      System.exit(1);
                      leaveWindow();
              else if(e.getActionCommand().equals("Search"))
                      //pass params to database                                 
                 }//end of else if
    } //end of method ActionPerformed
    }//End of class DissertationInterface

    I have done as stated, code compiles/executes but when I select the open file option on my GUI, the command prompt window freezes and no dialogue box is displayed!!!!

  • JFileChooser file filter and view does not display Drive letters

    This code displays only files that end in abc.xml, and directories. For example, "helloabc.xml" and directory "world" will display as hello and world, respectively.
    However, I am surprised to find that the drive letters are not displayed at all. eg. C:
    any insights?
    thanks,
    Anil
    import java.io.File;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    import javax.swing.filechooser.FileView;
    public class NoDrive {
         protected static final String ABC_FILE_EXTN = "abc.xml";
         public String selectFile(String function){
              File file = null;
              JFileChooser fc = new JFileChooser();
              fc.setFileFilter(new FileFilter() {
                   public boolean accept(File f) {
                        if (!f.isFile() || f.getName().endsWith(ABC_FILE_EXTN))
                             return true;                    
                        return false;
                   public String getDescription() {
                        return "ABC files";
              fc.setFileView(new FileView() {
                   public String getName(File f) {
                        String name = f.getName();
                        if (f.isFile() && name.endsWith(ABC_FILE_EXTN))
                             return name.substring(0, name.indexOf(ABC_FILE_EXTN));
                        return name;
              int returnVal = fc.showDialog(null, function);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   file = fc.getSelectedFile();
                   return file.getName();
              return null;
         public static void main(String[] args) {
              (new NoDrive()).selectFile("Open ABC");
    }

    OK. Here's the correct code:
        fc.setFileView(new FileView() {
          public String getName(File f) {
            String name = f.getName();
            if (f.isFile() && name.endsWith(ABC_FILE_EXTN)){
              return name.substring(0, name.indexOf(ABC_FILE_EXTN));
            else{
              return super.getName(f);
        });

Maybe you are looking for

  • A new start-up program in my Win 8.1: I can't stop it!

    Hi fellows. What about this article? In the last couple of days I've been getting loads of email from WinPatrol customers asking what is this strange new start-up program? The name is only numbers and no matter how many times I try to block or disabl

  • How to use ODBC SQLDriverConnect() without using tnsnames.ora file

    I have an ODBC application that connects to an Oracle 10g database. Currently, my SQLDriverConnect() function call uses the following connection string: DRIVER={Oracle in OraClient10g_home1}; DBQ=MyDB.world; DBA=W; UID=foo; PWD=bar This requires an e

  • MacBook hooked up to an LCD

    Hi All, I have a Vizio GV47L and an original MacBook. I have bought the mini-dvi to dvi adapter hooked up to a DVI-HDMI Cable. The picture shows up great, however there are black bars on each side of the LCD. The resolution I'm pushing to the LCD is

  • Download size of Solaris 10 x86 DVD ?

    Hi ! The last time I was here to download Sun Solaris 10, I was set back by the size of the download/time for that. If I do remember correctly it had 2 main image files each over 1 GB and 2 other add on files, summing over 4 GB. At that time I didn't

  • Firefox Spry Error (but not  in IE)

    Hey Guys, Can anyone help me troubleshoot this error I'm receiving on my Spry page. It's this line of code: var selIndex = selObj.selectedIndex; It's happening in Firefox, but not in IE (works fine in IE). The page URL is: http://www.spearsenterprise