Swing 组件中怎么实现当点击一个按钮时,打开一个文件夹

2025-01-07 04:22:29
推荐回答(2个)
回答1:

java 资源选择器

JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter); // 过滤器可以不要
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}

回答2:

java.awt.Desktop.getDesktop.open(new File("e:\\"));