user3089869
user3089869

Reputation: 229

Java Swing - Open dialog doesn't display the files present inside the directory

In Java Swing, i have a dialogue and a browse button. Once i click on browse, it allows the user to choose the corresponding directory. But the files present inside that directory are not getting displayed. It displays only the empty folder. How can i fix this ?

Upvotes: 0

Views: 443

Answers (2)

farhad rajaie
farhad rajaie

Reputation: 36

below complete code for jfilechosser

import java.awt.event.*;
import javax.swing.*;

public class FileChooserDemo  {


    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel panel=new JPanel();

        JButton Open = new JButton("Open a file...");
        Open.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                 JFileChooser fc= new JFileChooser();
                 fc.showOpenDialog(null);
                 fc.setVisible(true);

            }
        });

        panel.add(Open);

        frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true);
    }
}

good luck

Upvotes: 0

Tim B
Tim B

Reputation: 41210

In JFileChooser you have a number of options for setting up a filter on the file chooser.

Make sure that your filter by filename and by file type is set up correctly. (i.e. all filenames, both files and directories).

Upvotes: 2

Related Questions