开发者

How to browse folders in java?

开发者 https://www.devze.com 2023-01-03 01:39 出处:网络
I tried to create a JFileChooser but I don\'t understand how to set it to show di开发者_如何学JAVArectories only.JFileChooser f = new JFileChooser();

I tried to create a JFileChooser but I don't understand how to set it to show di开发者_如何学JAVArectories only.


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

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


Have look at this code snippet - that sounds promising.

The most intersting line is:

chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消