dusan1234
dusan1234

Reputation: 19

How to browse folders in java?

I tried to create a JFileChooser but I don't understand how to set it to show directories only.

Upvotes: 1

Views: 1477

Answers (3)

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56595

Apart from what Michael already suggested you might take a look at JIDE OSS, a free Swing components library, which amongst many other goodies provides a much nicer folder chooser component(FolderChooser).

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114767

Have look at this code snippet - that sounds promising.

The most intersting line is:

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

Upvotes: 0

Michael Borgwardt
Michael Borgwardt

Reputation: 346270

JFileChooser f = new JFileChooser();
f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

if(f.showOpenDialog(parent)== JFileChooser.APPROVE_OPTION) {      
    File result = f.getSelectedFile();
} else {
    ...
}

Upvotes: 3

Related Questions