Reputation: 229
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
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
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