JFileChooser : Files and Directories
I have a MenuItem name openMenuItem and its actionPerformed method is below :
private void openMenuItemActionPerformed(java.awt.event.ActionE vent evt) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.FILES_AN D_DIRECTORIES);
javax.swing.filechooser.FileFilter filter1 = new javax.swing.filechooser.FileFilter() {
public boolean accept(File file) {
String filename = file.getName();
return filename.endsWith(".mp3");
}
public String getDescription() {
return "*.mp3";
}
};
chooser.addChoosableFileFilter(filter1);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println(chooser.getSelectedFile());
} else {
System.out.println("No Selection ");
}
}
what i want is that i want to allow the user to select either a file or a directory. And if the user select a file just use the directory where that file is located.
Also i want double click to open the direcory.
How can i do these ?
Re: JFileChooser : Files and Directories
Look at the JFileChooser class and see what methods is has that can be of use to you.
Re: JFileChooser : Files and Directories
I tried to look it but didn't help.
I am newbie to it. I am looking for concrete answer.
@Norm thanx for your reply.
Re: JFileChooser : Files and Directories
Use Search or Google for sample code.
What did you try?
Re: JFileChooser : Files and Directories
Moved from 'New to Java'
db