Farhan Ghifari
Farhan Ghifari

Reputation: 1

How to open a folder windows in java aplication ? I want to insert path of file .txt in my application

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

Answers (1)

Amila
Amila

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

Related Questions