码迷,mamicode.com
首页 > 编程语言 > 详细

java Swing

时间:2015-06-19 16:53:30      阅读:151      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!