您的位置:首页 > 编程语言 > Java开发

java Swing 选择框

2015-06-19 15:33 459 查看
public class FileChoice {
private static JFileChooser fileChooser = null;
private static JFileChooser fileDown = null;
private static String filePath = "";
private static String outPath = "";
// 选择框

private static JFileChooser getFileChooser() {
if (fileChooser == null) {
fileChooser = new JFileChooser();
fileChooser.setFileFilter(null);
fileChooser.setFileFilter(new FileNameExtensionFilter(
"XLS and XLSX Files", "xls", "xlsx"));
fileChooser.setFont(new Font("Dialog", Font.PLAIN, 12));
fileChooser.setMultiSelectionEnabled(false);
}
return fileChooser;
}

public  String getUploadFile() {
int res = getFileChooser().showOpenDialog(null);
if (res == JFileChooser.APPROVE_OPTION) {
File file = getFileChooser().getSelectedFile();
filePath = file.getAbsolutePath();
System.out.println("ccccccccccccccccc:" + file.getAbsolutePath());
}
return filePath;
}

// 保存框
public static String getFileDown() {
if (fileDown == null) {
fileDown = new JFileChooser();
fileDown.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
int returnVal = fileDown.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose diriction: "
+ fileDown.getSelectedFile().getPath());
outPath = fileDown.getSelectedFile().getPath() + "\\";
System.out.println(outPath + "ddddddddd");
}
return outPath;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  选择框