Hi everyone,
In my simple GUI, I have a part where I use JFileChooser to let user browse for a file. The problem is that when browsing for that file, in order to open a sub folder, user has always to double click that the main folder to open the sub folder. What I want is that user can either double click the main folder or hit Enter (when that main folder is highlight) to open the sub folder.
Here is the code for the JFileChooser part:
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".txt") || f.isDirectory();
}
public String getDescription() {
return "TXT Files";
}});
int r = chooser.showDialog(new JFrame(),"Select .TXT File");
if (r == JFileChooser.APPROVE_OPTION) {
chooser.getSelectedFile().getName();
}
if(r == JFileChooser.CANCEL_OPTION) System.exit(0);
At this point, in order to open a sub folder, I need to double click the main folder. If I hit Enter (when that main folder is selected (highlight), it will give me an error. How can i get the Enter key to open the sub folder?
Thanks.