标签:选择框
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; } }
标签:选择框
原文地址:http://blog.csdn.net/dst111188/article/details/46561923