Reputation: 1
How to make a button that can open folder option and search .txt file.
I want to insert path (example : c:/documents
) by open window if folder option. so the user of my aplication just click it and not type it in the field text.
by the way I use netbeans as my IDE.
please help me. thank you.
Upvotes: 0
Views: 113
Reputation: 5213
This can be done with JFileChooser. Official Tutorial is the best place to start.
Important steps are:
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
}
Upvotes: 1