Swing 打开选择文件对话框

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

// 打开文件选择窗口
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
public boolean accept(File f) {
return f.getName().toLowerCase().endsWith(".txt") || f.isDirectory();
}

public String getDescription() {
return "classify data";
}
});

int r = chooser.showOpenDialog(new JFrame());
if (r == JFileChooser.APPROVE_OPTION) {
File f=chooser.getSelectedFile();
} else {
//没有选择文件
}
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

你可能感兴趣的:(swing)