首页 > 编程语言 > 详细

java Swing

时间:2015-06-19 16:51:20      阅读:161      评论:0      收藏:0      [点我收藏+]
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;
		}
}

java Swing

原文:http://blog.csdn.net/dst111188/article/details/46561923

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!